#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;
bool b = true;
vector<long long> w, h, comp;
long long wsum = 0;
for(long long i = 0; i < n; i++){
cin >> x;
h.push_back(x);
if (x != 1 && x != 2) b = false;
}
for(long long i = 0; i < n; i++){
cin >> x;
wsum += x;
wsum = wsum % MOD;
w.push_back(x);
}
if(b){
for(long long 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(long long k : comp) {
k = k % MOD;
ans += k*(k+1);
ans = ans % MOD;
}
ans += wsum*(wsum+1)/2;
ans = ans % MOD;
cout << ans;}
else{
ans = wsum * (wsum+1);
ans = ans%1000000007;
ans *= h[0];
ans = ans%1000000007;
ans *= (h[0]+1);
ans = ans%1000000007;
while(ans % 4 != 0){
ans += 1000000007;
}
ans /= 4;
cout << ans;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
36 ms |
1944 KB |
Output is correct |
4 |
Correct |
61 ms |
3512 KB |
Output is correct |
5 |
Correct |
65 ms |
3508 KB |
Output is correct |
6 |
Correct |
62 ms |
3524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
9 ms |
688 KB |
Output is correct |
3 |
Correct |
54 ms |
2428 KB |
Output is correct |
4 |
Correct |
97 ms |
4380 KB |
Output is correct |
5 |
Correct |
83 ms |
4468 KB |
Output is correct |
6 |
Correct |
1 ms |
296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
10 ms |
724 KB |
Output is correct |
4 |
Correct |
44 ms |
2340 KB |
Output is correct |
5 |
Correct |
82 ms |
4384 KB |
Output is correct |
6 |
Correct |
93 ms |
4484 KB |
Output is correct |
7 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
2 ms |
312 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |