Submission #668810

# Submission time Handle Problem Language Result Execution time Memory
668810 2022-12-05T03:01:06 Z vuavisao Modsum (NOI12_modsum) C++14
25 / 25
1 ms 340 KB
#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

modsum.cpp: In function 'int32_t main()':
modsum.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen("sum.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
modsum.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen("sum.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 324 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 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 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 212 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 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 332 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 332 KB Output is correct