在Vijos上测试成功。
测试数据 #0: Accepted, time = 0 ms, mem = 25284 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 25284 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 25280 KiB, score = 10
测试数据 #3: Accepted, time = 54 ms, mem = 25288 KiB, score = 10
测试数据 #4: Accepted, time = 89 ms, mem = 25284 KiB, score = 10
测试数据 #5: Accepted, time = 589 ms, mem = 25288 KiB, score = 10
测试数据 #6: Accepted, time = 628 ms, mem = 25280 KiB, score = 10
测试数据 #7: Accepted, time = 593 ms, mem = 25280 KiB, score = 10
测试数据 #8: Accepted, time = 800 ms, mem = 25280 KiB, score = 10
测试数据 #9: Accepted, time = 824 ms, mem = 25280 KiB, score = 10
有点慢。
模拟一下就好了。
一开始用cin/cout和模超了5个点。后来改用scanf/printf和减法就好了。。。。(模这个东西真是慢)
大循环是循环每个楼层。
然后计算指示牌的和(就加一下就好了)。
然后扫描该层向上楼梯,存到一个数组里。
然后模一下就找到下一个楼梯。
循环下去就好了。
#include <stdio.h> #include <string.h> using namespace std; #define N 10005 #define M 105 typedef long long ll; ll n, m, now, i, j; ll up[N][M], card[N][M], louti[M], loutitot[N], lt[N][M]; ll mod(ll s, ll m) { ll r = s; while(r>=m) r-=m; return r; } int main() { scanf("%lld%lld", &n, &m); memset(loutitot,0,sizeof(loutitot)); for(i=1;i<=n;i++) for(j=0;j<m;j++) scanf("%d%d", &up[i][j], &card[i][j]); scanf("%d", &now); ll sum = 0; for(i=1;i<=n;i++) { sum = mod(sum+card[i][now],20123); ll d = card[i][now]; ll k = 0; for(j=now;j<m;j++) if(up[i][j]) louti[++k] = j; for(j=0;j<now;j++) if(up[i][j]) louti[++k] = j; d=mod(d,k); if(d==0) d=k; now=louti[d]; } printf("%lld", sum); return 0; }