Submission #668810

#TimeUsernameProblemLanguageResultExecution timeMemory
668810vuavisaoModsum (NOI12_modsum)C++14
25 / 25
1 ms340 KiB
#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)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...