# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
668810 | vuavisao | Modsum (NOI12_modsum) | C++14 | 1 ms | 340 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define ll long long
using namespace std;
const int N = 1e3 + 10;
int n;
int a[N], b[N];
int dp[N][10];
int res;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen("sum.inp", "r")) {
freopen("sum.inp", "r", stdin);
freopen("sum.out", "w", stdout);
}
cin >> n;
for(int i = 1; i <= n; ++ i) cin >> a[i] >> b[i];
dp[0][0] = 1;
for(int i = 0; i < n; ++ i) {
for(int j = 0; j < 5; ++ j) {
if(dp[i][j] == 0) continue;
for(int k = a[i + 1]; k <= b[i + 1]; ++ k) dp[i + 1][(j + k) % 5] += dp[i][j];
}
}
int res = 0;
auto sqr = [&] (int val) { return val * val; };
for(int i = 0; i < 5; ++ i) {
int sqr_i = sqr(i);
int double_sqr_i = sqr(sqr_i);
res += dp[n][i] * ((double_sqr_i + 2 * sqr_i) % 5 + 1);
}
cout << res;
return 0;
}
/// Code by vuavisao
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |