QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#727345 | #881. Gig Combinatorics | gambit# | WA | 1ms | 5812kb | C++17 | 1.6kb | 2024-11-09 12:52:03 | 2024-11-09 12:52:04 |
Judging History
answer
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
ll arr[1000001];
ll preSum[1000001][2]; // [i][1, 2]
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int n; cin >> n;
ll total3=0;
for(int i=0;i<n;i++){
cin>>arr[i];
if(arr[i]==3) total3++;
}
vector<pair<ll, ll>> lastTwo;
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;
// cout << lastTwo[i].first*lastTwo[i].second << ' ';
if(i>=1) {
ll last1 = preSumfor1;
if(i>=2) {
last1 = lastTwo[i-1].first;
cnt += (preSumfor1-last1)*lastTwo[i].second*2; // length>2
// cout << (preSumfor1-last1)*lastTwo[i].second*2 << ' ';
}
cnt += last1*lastTwo[i].second; // length==2
// cout << last1*lastTwo[i].second << ' ';
}
preSumfor1 += lastTwo[i].first;
cnt %= 1'000'000'007;
// cout << cnt << '\n';
}
cout << cnt;
return 0;
}
/*
10
1 2 1 2 3 1 2 3 2 3
*/
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5812kb
input:
9 1 1 1 2 2 2 3 3 3
output:
63
result:
ok answer is '63'
Test #2:
score: 0
Accepted
time: 1ms
memory: 5588kb
input:
8 1 2 1 2 3 1 2 3
output:
15
result:
ok answer is '15'
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 5660kb
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:
11565538
result:
wrong answer expected '265702265', found '11565538'