# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
938959 |
2024-03-06T01:45:25 Z |
riariti |
Modsum (NOI12_modsum) |
C++17 |
|
1 ms |
604 KB |
#line 1 "MODSUM.cpp"
#include <bits/stdc++.h>
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >> n;
std::vector<int> v(n), w(n);
for (int i = 0; i < 2 * n; i++) {
auto k = i / 2;
std::cin >> (i % 2 ? w[k] : v[k]);
}
constexpr int K = 5;
std::array<int, K> cnt{};
// sum of 0 is 1
cnt[0] = 1;
for (int i = 0; i < n; i++) {
std::array<int, 5> cur{};
for (int j = v[i]; j <= w[i]; j++) {
for (int k = 0; k < K; k++) {
// basically what values if we add from before
// i.e 1 2 3, then 2 3
// 1 2
// 1 3
// 2 2
// 2 3
// 3 2
// 3 3
// => i.e j = 1 and if we change the variable to one of the mod
// 5s then we see the sum changes and thus also we have to add
// the cnt of that (number of values of that mod 5)
cur[(j + k) % K] += cnt[k];
}
}
std::swap(cnt, cur);
}
std::int64_t ans = 0;
for (int i = 0; i < 5; i++) {
std::int64_t v = std::pow(i, 4) + 2 * std::pow(i, 2);
ans += cnt[i] * (v % 5 + 1);
}
std::cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |