# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1010988 | cpdreamer | Fancy Fence (CEOI20_fancyfence) | C++17 | 1 ms | 348 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>
#include <ext/pb_ds/assoc_container.hpp>
#include <utility>
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
const int max_n=INT_MAX;
const int inf=1e8;
typedef long long ll;
#define LLM LONG_LONG_MAX
#define pb push_back
#define F first
#define P pair
#define all(v) v.begin(),v.end()
#define V vector
#define S second
const long long MOD = 1e9+7; // 1e9 + 7
void file(){
freopen("input.txt.txt","r",stdin);
freopen("output.txt.txt","w",stdout);
}
void setio(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
bool check(V<P<int,int>>&vp,int r1,int r2,int l){
for(int i=r1;i<=r2;i++){
if(min(vp[i].F,vp[i].S)<l)
return false;
}
return true;
}
void solve() {
int n;
cin>>n;
int A[n];
int B[n];
for(int i=0;i<n;i++){
cin>>A[i];
}
for(int i=0;i<n;i++){
cin>>B[i];
}
ll s=0;
ll c=0;
ll current=0;
V<ll>vp;
bool flag=false;
for(int i=0;i<n;i++) {
if (A[i] == 1) {
if (flag) {
vp.pb(current);
}
current = 0;
flag = false;
}
else{
flag=true;
current+=B[i];
}
s+=B[i];
}
if(flag)
vp.pb(current);
ll a;
if(s%2==0){
a=s/2;
a=a%MOD;
a=(a*(s+1))%MOD;
}
else{
a=(s+1)/2;
a=a%MOD;
a=(a*s)%MOD;
}
c=(c+a)%MOD;
for(auto u:vp){
ll b=u;
b=b%MOD;
b=(b*(u+1))%MOD;
c=(c+b)%MOD;
}
cout<<c<<endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//file();
solve();
return 0;
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |