# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
731825 | 2023-04-28T04:03:25 Z | racsosabe | Modsum (NOI12_modsum) | C++14 | 1 ms | 468 KB |
#include <bits/stdc++.h> using namespace std; const int N = 1000 + 5; int n; int L[N]; int R[N]; bool vis[N][5][5]; int memo[N][5][5]; int DP(int pos, int sum_sq, int sum){ if(pos == n) return ((sum_sq + 1) * (sum_sq + 1) + 4) % 5 + 1; if(vis[pos][sum_sq][sum]) return memo[pos][sum_sq][sum]; int res = 0; for(int x = L[pos]; x <= R[pos]; x++){ int new_sum_sq = (sum_sq + 2 * sum * x + x * x) % 5; int new_sum = (sum + x) % 5; res += DP(pos + 1, new_sum_sq, new_sum); } vis[pos][sum_sq][sum] = true; return memo[pos][sum_sq][sum] = res; } int main() { scanf("%d", &n); for(int i = 0; i < n; i++) scanf("%d %d", L + i, R + i); printf("%d\n", DP(0, 0, 0)); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 468 KB | Output is correct |
2 | Correct | 1 ms | 468 KB | Output is correct |
3 | Correct | 1 ms | 468 KB | Output is correct |
4 | Correct | 1 ms | 468 KB | Output is correct |
5 | Correct | 1 ms | 468 KB | Output is correct |