제출 #1027922

#제출 시각아이디문제언어결과실행 시간메모리
1027922IssaFlooding Wall (BOI24_wall)C++17
0 / 100
5 ms23948 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define ent "\n" const int maxn = 1e6 + 100; const ll INF = (ll)1e18 + 100; const int inf = 1e9 + 100; const int MOD = 1e9 + 123; const int maxl = 26; const int P = 31; int n; int a[maxn][2]; vector<int> dp[maxn]; void test(){ cin >> n; vector<int> s = {-1}; for(int i = 1; i <= n; i++){ cin >> a[i][0]; } for(int i = 1; i <= n; i++){ cin >> a[i][1]; s.push_back(a[i][0]); s.push_back(a[i][1]); } sort(s.begin(), s.end()); s.resize(unique(s.begin(), s.end()) - s.begin()); for(int i = 1; i <= n; i++){ a[i][0] = lower_bound(s.begin(), s.end(), a[i][0]) - s.begin(); a[i][1] = lower_bound(s.begin(), s.end(), a[i][1]) - s.begin(); if(a[i][0] > a[i][1]) swap(a[i][0], a[i][1]); } dp[0] = vector<int>(s.size(), 0); dp[0][0] = 1; for(int i = 1; i <= n; i++){ dp[i] = dp[i-1]; for(int j = s.size()-1; j >= 0; j--){ if(s[j] > a[i][1]){ dp[i][j] = dp[i][j] * 2 % MOD; } else if(s[j] > a[i][0]){ dp[i][a[i][1]] = (dp[i][a[i][1]] + dp[i-1][j]) % MOD; } else{ dp[i][a[i][1]] = (dp[i][a[i][1]] + dp[i-1][j]) % MOD; dp[i][a[i][0]] = (dp[i][a[i][0]] + dp[i-1][j]) % MOD; dp[i][j] = 0; } } } vector<int> d = vector<int>(s.size(), 0); d[0] = 1; ll ans = 0; for(int i = n; i > 0; i--){ ll sum1 = 0, sum2 = 0; for(int j = s.size() - 1; j >= 0; j--){ sum1 = (sum1 + dp[i-1][j]) % MOD; ll cnt = (1ll * d[j] * sum1 + dp[i-1][j] * sum2) % MOD; sum2 = (sum2 + d[j]) % MOD; if(s[j] > a[i][1]){ ans = (ans + 1ll * (s[j] - a[i][1]) * cnt) % MOD; } if(s[j] > a[i][0]){ ans = (ans + 1ll * (s[j] - a[i][0]) * cnt) % MOD; } } for(int j = s.size()-1; j >= 0; j--){ if(s[j] > a[i][1]){ d[j] = d[j] * 2 % MOD; } else if(s[j] > a[i][0]){ d[a[i][1]] = (d[a[i][1]] + d[j]) % MOD; } else{ d[a[i][1]] = (d[a[i][1]] + d[j]) % MOD; d[a[i][0]] = (d[a[i][0]] + d[j]) % MOD; d[j] = 0; } } } cout << ans; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; t = 1; while(t--) test(); cout << ent; }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...