QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#727303 | #881. Gig Combinatorics | gambit# | WA | 0ms | 3556kb | C++17 | 1.3kb | 2024-11-09 12:37:06 | 2024-11-09 12:37:07 |
Judging History
answer
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int n; cin >> n;
int arr[n];
int total3=0;
for(int i=0;i<n;i++){
cin>>arr[i];
if(arr[i]==3) total3++;
}
vector<pair<ll, ll>> lastTwo;
ll preSum[n][2]; // [i][1, 2]
preSum[0][0]=preSum[0][1]=0;
if(arr[0]==1) preSum[0][0]++;
else if(arr[0]==2) preSum[0][1]++;
else lastTwo.push_back({0, total3});
for(int i=1;i<n;i++){
preSum[i][0] = preSum[i-1][0];
preSum[i][1] = preSum[i-1][1];
if(arr[i]==1) preSum[i][0]++;
else if(arr[i]==3) preSum[i][1]++;
else lastTwo.push_back({preSum[i][0], total3-preSum[i][1]});
}
ll cnt=0, preSumfor1=0;
for(int i=0;i<lastTwo.size();i++){
cnt += lastTwo[i].first*lastTwo[i].second;
if(i>=1) {
ll last1 = preSumfor1;
if(i>=2) {
last1 = preSumfor1 - lastTwo[i-2].first;
cnt += lastTwo[i-2].first*lastTwo[i].second*2; // length>2
}
cnt += last1*lastTwo[i].second; // length==2
}
preSumfor1 += lastTwo[i].first;
cnt %= 1'000'000'007;
}
cout << cnt;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3544kb
input:
9 1 1 1 2 2 2 3 3 3
output:
63
result:
ok answer is '63'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
8 1 2 1 2 3 1 2 3
output:
15
result:
ok answer is '15'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3556kb
input:
310 1 2 3 2 2 3 2 3 2 1 2 3 2 3 2 1 2 1 1 2 1 2 3 3 2 2 3 3 2 2 1 1 2 3 2 2 3 2 3 2 1 2 3 2 3 2 1 2 1 1 2 1 2 3 3 2 2 3 3 2 2 2 1 2 3 2 2 3 2 3 2 1 2 3 2 3 2 1 2 1 1 2 1 2 3 3 2 2 3 3 2 2 2 1 2 3 2 2 3 2 3 2 1 2 3 2 3 2 1 2 1 1 2 1 2 3 3 2 2 3 3 2 2 1 1 2 3 2 2 3 2 3 2 1 2 3 2 3 2 1 2 1 1 2 1 2 3 3 ...
output:
6079950
result:
wrong answer expected '265702265', found '6079950'