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;
const long long MOD = 1e9+7;
int main(){
long long n; cin >> n;
long long x;
long long ans = 0;
vector<long long> w, h, comp;
long long wsum = 0;
for(long long i = 0; i < n; i++){
cin >> x;
h.push_back(x);
}
for(long long i = 0; i < n; i++){
cin >> x;
wsum += x;
w.push_back(x);
}
for(int i = 0; i < n; i++){
if(h[i] == 2){
if(i == 0) comp.push_back(w[i]);
else if(h[i-1] == 2) comp.back() += w[i];
else comp.push_back(w[i]);
}
}
for(int k : comp) {
k = k % MOD;
ans += k*(k+1);
ans = ans % MOD;
}
wsum = wsum % MOD;
ans += wsum*(wsum+1)/2;
ans = ans % MOD;
cout << ans;
}
# | 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... |