[NOIP2012 普及组] 寻宝

发布时间 2023-07-05 10:52:36作者: B_C_O

思路:模拟

必须mod20123,不然就有可能会爆掉!!!!!

上代码:

#include<iostream>
#define int long long
using namespace std;
bool whether[10001][101];
int s[10001][101],T[10001];
signed main()
{
	int n,m,S,w,ans=0;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cin>>whether[i][j]>>s[i][j];
			if(whether[i][j]) T[i]++;
		}
	}
	cin>>w;
	for(int i=0;i<n;i++)
	{
		ans=(ans+s[i][w]%20123)%20123;
		S=s[i][w]%T[i];
		if(S==0) S=T[i];
		while(S)
		{
			if(whether[i][w]) S--;
			if(S) w++;
			w%=m;
		}
	}
	cout<<ans%20123;
	return 0;
}

完结撒花!!!