# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1027950 | Otalp | Flooding Wall (BOI24_wall) | C++14 | 2571 ms | 790868 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pb push_back
#define ff first
#define ss second
const ll mod = 1e9 + 7;
ll dd[500100];
ll a[500100][2];
ll dp[200100];
int ds[10001][20001];
int st[500100];
ll ans = 0;
int n;
void solve(){
cin>>n;
vector<ll> d;
for(int k=0; k<2; k++){
for(int i=1; i<=n ; i++){
cin>>a[i][k];
d.pb(a[i][k]);
}
}
st[0] = 1;
for(int i=1; i<=n; i++){
st[i] = st[i-1] * 2 % mod;
}
sort(d.begin(), d.end());
for(int i=0; i<d.size(); i++) ds[n+1][i] = 0, dd[i] = 1;
for(int i=n; i>=1; i--){
for(int j=0; j<d.size(); j++){
int asd = 0;
for(int k=0; k<2; k++){
if(a[i][k] < d[j]){
asd ++;
}
}
dd[j] = dd[j] * asd % mod;
ds[i][j] = (st[n-i+1] - dd[j] + mod) % mod;
}
}
//cout<<"asdasdasd\n";
//for(int i=1; i<=n; i++){
// for(int j=0; j<d.size(); j++){
// cout<<ds[i][j]<<' ';
// }
// cout<<'\n';
//}
ll ans = 0;
for(int i=0; i<d.size(); i++) dp[i] = 0, dd[i] = 1;
for(int i=1; i<=n; i++){
for(int j=0; j<d.size(); j++){
int asd = 0;
for(int k=0; k<2; k++){
if(a[i][k] < d[j]){
asd ++;
//cout<<i<<' '<<d[j]<<' '<<a[i][k]<<' '<<dp[j] * (ds[i+1][j]) % mod * (d[j] - d[j-1]) % mod<<'\n';
ans = (ans + dp[j] * ds[i+1][j] % mod * (d[j] - d[j-1]) % mod) % mod;
}
}
dd[j] = dd[j] * asd % mod;
dp[j] = (st[i] - dd[j] + mod) % mod;
}
}
cout<<ans;
}
signed main(){
solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |