제출 #1314657

#제출 시각아이디문제언어결과실행 시간메모리
1314657joshjuice나머지들의 합 (NOI12_modsum)C++20
25 / 25
1 ms332 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef deque<int> dqi;
typedef pair<ll, ll> pll;

#define ppf pop_front
#define pf push_front
#define pb push_back
#define fr first
#define sc second
#define all(a) a.begin(), a.end()
#define sr(a) sort(all(a))
#define sz(a) a.size()
#define rep(x, a, b) for(auto x=a;(a<b?x<b:x>b);(a<b?x++:x--))
#define mnto(x,y) x = min(x, (__typeof__(x))y)
#define mxto(x,y) x = max(x, (__typeof__(x))y)

const ll INF1 = 1e18;
const ll INF2 = 1e15;
const ll INF3 = 1e14;

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int n;
  cin >> n;
  vi v(n), w(n);
  rep(i, 0, n) cin >> v[i] >> w[i];
  vll dp(5, 0);
  dp[0] = 1;
  rep(i, 0, n) {
    vll ndp(5, 0);
    rep(r, 0, 5) {
      rep(x, v[i], w[i]+1) {
        ndp[(r+x) % 5] += dp[r];
      }
    }
    dp = ndp;
  }
  int fmod[5];
  rep(r, 0, 5) {
    fmod[r] = ((1LL*r*r*r*r + 2LL*r*r) % 5) + 1;
  }
  ll ans = 0;
  rep(r, 0, 5) ans += dp[r] * fmod[r];
  cout << ans;
}
#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...