QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#589767 | #1647. Divisible by 3 | ucup-team3474# | WA | 1ms | 5824kb | C++20 | 1.4kb | 2024-09-25 20:03:22 | 2024-09-25 20:03:27 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+10,mod=998244353;
typedef long long ll;
typedef pair<ll,ll> PII;
ll n,m,k;
ll a[N],b[N];
char s[N];
ll dp[N][3][3][3];
void __(){
cin>>n;
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
a[i]%=3;
// cout<<a[i]<<" ";
}
// cout<<endl;
ll sum=0;
for(int i=0;i<=n;i++){
// dp[i+1][a[i]][a[i]][a[i]]=1;
for(int j=0;j<3;j++){
for(int k=0;k<3;k++) sum+=dp[i][j][k][0];
}
// cout<<sum<<endl;
dp[i][0][0][0]++;
// if(a[i]==0) dp[i+1][0][0][0]=1;
// else if(a[i]==1) dp[i+1][1][0][0]=1;
// else dp[i+1][0][1][0]=1;
for(int j=0;j<3;j++){
for(int k=0;k<3;k++){
for(int u=0;u<3;u++){
if(a[i]==0){
dp[i+1][j][k][u]+=dp[i][j][k][u];
}else if(a[i]==1){
dp[i+1][(j+1)%3][k][(u+j+k*2)%3]+=dp[i][j][k][u];
}else{
dp[i+1][j][(k+1)%3][(u+2*k*2+j*2)%3]+=dp[i][j][k][u];
}
}
}
}
}
// for(int i=1;i<=n;i++) if(a[i]==0) sum--;
cout<<sum<<endl;
}
int main(){
// ios::sync_with_stdio(0);
// cin.tie(0);
int _=1;
// cin>>_;
while(_--){
__();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5692kb
input:
3 5 23 2021
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 0ms
memory: 5824kb
input:
5 0 0 1 3 3
output:
15
result:
ok single line: '15'
Test #3:
score: 0
Accepted
time: 1ms
memory: 5680kb
input:
10 0 1 2 3 4 5 6 7 8 9
output:
20
result:
ok single line: '20'
Test #4:
score: 0
Accepted
time: 1ms
memory: 5656kb
input:
1 901418150
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 1ms
memory: 5820kb
input:
2 373642622 952441803
output:
3
result:
ok single line: '3'
Test #6:
score: 0
Accepted
time: 1ms
memory: 5748kb
input:
3 255932511 384728982 789675559
output:
6
result:
ok single line: '6'
Test #7:
score: -100
Wrong Answer
time: 1ms
memory: 5772kb
input:
4 433189692 522048869 125182076 157942182
output:
7
result:
wrong answer 1st lines differ - expected: '6', found: '7'