Submission #1106993

#TimeUsernameProblemLanguageResultExecution timeMemory
1106993VinhLuuFlooding Wall (BOI24_wall)C++17
25 / 100
179 ms92772 KiB
#include <bits/stdc++.h> //#define int long long #define ll long long #define all(lpv) lpv.begin(), lpv.end() #define fi first #define se second using namespace std; typedef pair<int,int> pii; const int N = 5e5 + 25; //const int oo = -1e16; const int mod = 1e9 + 7; int n, m, a[N], b[N]; void add(int &x,int y){ x = (x + y) % mod; } namespace sub2{ int f[5005][5005], g[5005][5005]; void solve(){ vector<int> rrh; for(int i = 1; i <= n; i ++){ rrh.push_back(a[i]); rrh.push_back(b[i]); } sort(all(rrh)); rrh.resize(unique(all(rrh)) - rrh.begin()); for(int i = 1; i <= n; i ++){ a[i] = lower_bound(all(rrh), a[i]) - rrh.begin() + 1; b[i] = lower_bound(all(rrh), b[i]) - rrh.begin() + 1; } m = rrh.size(); f[0][0] = 1; g[n + 1][0] = 1; for(int i = 0; i <= n; i ++){ for(int j = 0; j <= m; j ++) if(f[i][j]){ add(f[i + 1][max(j, a[i + 1])], f[i][j]); add(f[i + 1][max(j, b[i + 1])], f[i][j]); } for(int j = m - 1; j >= 1; j --) add(f[i][j], f[i][j + 1]); } for(int i = n + 1; i >= 1; i--){ for(int j = 0; j <= m; j ++) if(g[i][j]){ add(g[i - 1][max(j, a[i - 1])], g[i][j]); add(g[i - 1][max(j, b[i - 1])], g[i][j]); } for(int j = m - 1; j >= 1; j --) add(g[i][j], g[i][j + 1]); } int ans = 0; for(int i = 2; i < n; i ++){ for(int j = 1; j <= m; j ++){ int high = rrh[j - 1]; ll cnt = (1ll * (f[i - 1][j] + mod - f[i - 1][j + 1]) % mod * g[i + 1][j + 1] % mod + 1ll * (g[i + 1][j] + mod - g[i + 1][j + 1]) % mod * f[i - 1][j] % mod) % mod; if(high > rrh[a[i] - 1]){ ll val = 1ll * cnt * (high - rrh[a[i] - 1]) % mod; add(ans, val); } if(high > rrh[b[i] - 1]){ ll val = 1ll * cnt * (high - rrh[b[i] - 1]) % mod; add(ans, val); } } } cout << ans; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "v" if(fopen(task ".inp","r")){ freopen(task ".inp","r",stdin); freopen(task ".out","w",stdout); } cin >> n; for(int i = 1; i <= n; i ++) cin >> a[i]; for(int i = 1; i <= n; i ++) cin >> b[i]; sub2 :: solve(); } /* 10 1 2 3 4 5 6 7 8 9 10 10 9 8 7 6 5 4 3 2 1 */

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:82:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |     freopen(task ".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:83:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |     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...