Submission #1274535

#TimeUsernameProblemLanguageResultExecution timeMemory
1274535icebearFlooding Wall (BOI24_wall)C++20
25 / 100
1595 ms1114112 KiB
// ~~ icebear ~~ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; typedef pair<int, ii> iii; template<class T> bool minimize(T &a, const T &b) { if (a > b) return a = b, true; return false; } template<class T> bool maximize(T &a, const T &b) { if (a < b) return a = b, true; return false; } #define FOR(i,a,b) for(int i=(a); i<=(b); ++i) #define FORR(i,a,b) for(int i=(a); i>=(b); --i) #define REP(i, n) for(int i=0; i<(n); ++i) #define RED(i, n) for(int i=(n)-1; i>=0; --i) #define MASK(i) (1LL << (i)) #define BIT(S, i) (((S) >> (i)) & 1) #define mp make_pair #define pb push_back #define fi first #define se second #define all(x) x.begin(), x.end() #define task "icebear" const int MOD = 1e9 + 7; const int inf = 1e9 + 27092008; const ll INF = 1e18 + 27092008; const int N = 1e4 + 5; int n, a[N], b[N]; int dpL[N][N*2], dpR[N][N*2]; int pL[N*2], pR[N*2]; vector<int> compress; void init(void) { cin >> n; FOR(i, 1, n) cin >> a[i], compress.pb(a[i]); FOR(i, 1, n) cin >> b[i], compress.pb(b[i]); sort(all(compress)); compress.resize(unique(all(compress)) - compress.begin()); FOR(i, 1, n) a[i] = lower_bound(all(compress), a[i]) - compress.begin(); FOR(i, 1, n) b[i] = lower_bound(all(compress), b[i]) - compress.begin(); } void process(void) { dpL[0][0] = dpR[n + 1][0] = 1; FOR(i, 0, n - 1) FOR(j, 0, 20000) { (dpL[i + 1][max(a[i + 1], j)] += dpL[i][j]) %= MOD; (dpL[i + 1][max(b[i + 1], j)] += dpL[i][j]) %= MOD; } FORR(i, n + 1, 2) FOR(j, 0, 20000) { (dpR[i - 1][max(a[i - 1], j)] += dpR[i][j]) %= MOD; (dpR[i - 1][max(b[i - 1], j)] += dpR[i][j]) %= MOD; } int ans = 0; FOR(i, 2, n - 1) { FOR(j, 1, 20000) pL[j] = (pL[j - 1] + dpL[i - 1][j]) % MOD; FOR(j, 1, 20000) pR[j] = (pR[j - 1] + dpR[i + 1][j]) % MOD; // int res = 0; FOR(j, 1, 20000) if (dpL[i - 1][j] > 0) { int v1 = max(0, compress[j] - compress[a[i]]); int v2 = max(0, compress[j] - compress[b[i]]); (ans += 1LL * (v1 + v2) * dpL[i - 1][j] % MOD * (pR[20000] - pR[j - 1] + MOD) % MOD) %= MOD; } FOR(k, 1, 20000) if (dpR[i + 1][k] > 0) { int v1 = max(0, compress[k] - compress[a[i]]); int v2 = max(0, compress[k] - compress[b[i]]); (ans += 1LL * (v1 + v2) * dpR[i + 1][k] % MOD * (pL[20000] - pL[k] + MOD) % MOD) %= MOD; } // cout << i << ' ' << res << '\n'; } cout << ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int tc = 1; // cin >> tc; while(tc--) { init(); process(); } return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:90:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:91:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |         freopen(task".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...
#Verdict Execution timeMemoryGrader output
Fetching results...