ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#197336 | #2774. 石头剪刀布 | wosile | 100 | 154ms | 20728kb | C++11 | 1.8kb | 2023-11-11 11:37:45 | 2023-11-11 12:12:23 |
answer
#include<bits/stdc++.h>
using namespace std;
int a[500005],b[500005];
typedef long long ll;
struct stats{
int c[3];
stats operator +(const stats &o)const{
stats ans;
for(int i=0;i<3;i++)ans.c[i]=c[i]+o.c[i];
return ans;
}
stats operator -(const stats &o)const{
stats ans;
for(int i=0;i<3;i++)ans.c[i]=c[i]-o.c[i];
return ans;
}
};
stats cons(int x){
// printf("cons %d\n",x);
stats ans;
for(int i=0;i<3;i++)ans.c[i]=(i==x?1:0);
return ans;
}
stats pre[500005];
int pos[500005];
vector<int>v[500005];
int main(){
int n,m;
ll k;
scanf("%d%d%lld",&n,&m,&k);
int gcd=__gcd(n,m);
ll lcm=1LL*n*m/gcd;
for(int i=0;i<n;i++)scanf("%d",&a[i]);
for(int j=0;j<m;j++)scanf("%d",&b[j]);
for(int j=0;j<gcd;j++){
for(int tmp=j,cnt=0,lst=m;cnt<m/gcd;lst=tmp,tmp=(tmp+n)%m,cnt++){
pre[tmp]=pre[lst]+cons(b[tmp]);
// printf("%d %d %d %d %d\n",tmp,lst,pre[tmp].c[0],pre[tmp].c[1],pre[tmp].c[2]);
pos[tmp]=cnt;
v[j].push_back(tmp);
}
}
ll z=k/lcm;
ll ans1=0,ans2=0;
for(int i=0;i<n;i++){
int p=i%gcd;
p=v[p][m/gcd-1];
// printf("%d\n",p);
// printf("%d %d %d\n",pre[p].c[0],pre[p].c[1],pre[p].c[2]);
ans1+=pre[p].c[(a[i]+1)%3];
ans2+=pre[p].c[(a[i]+2)%3];
}
// printf("%d %d\n",ans1,ans2);
ans1*=z;
ans2*=z;
k-=z*lcm;
for(int i=0;i<n;i++){
int cnt=k/n+(i<k%n?1:0);
if(!cnt)continue;
// printf("i=%d,cnt=%d\n",i,cnt);
int pl=pos[i%m];
int r=i%gcd;
int pr=(pl+cnt-1+m/gcd)%(m/gcd);
// printf("%d %d %d %d\n",pl,pr,v[r][pl],v[r][pr]);
stats tmp;
pl=(pl-1+m/gcd)%(m/gcd);
if(pl<=pr)tmp=pre[v[r][pr]]-pre[v[r][pl]];
else tmp=pre[v[r][m/gcd-1]]-pre[v[r][pl]]+pre[v[r][pr]];
ans1+=tmp.c[(a[i]+1)%3];
ans2+=tmp.c[(a[i]+2)%3];
// printf("ans1=%d,ans2=%d\n",ans1,ans2);
}
printf("%lld %lld",ans1,ans2);
return 0;
//quod erat demonstrandum
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 7ms
memory: 13032kb
input:
1085 1454 9313630 1 0 0 1 1 2 0 1 0 0 0 0 0 2 2 0 0 0 2 1 1 1 2 1 2 0 0 1 2 2 1 2 2 0 0 1 1 0 0 1 0 ...
output:
3096226 3107344
result:
ok single line: '3096226 3107344'
Test #2:
score: 10
Accepted
time: 0ms
memory: 13004kb
input:
1242 884 7691408 2 2 0 1 0 2 0 2 2 2 2 1 2 0 0 2 1 0 0 1 2 0 2 2 0 2 0 0 1 1 1 0 1 1 1 2 1 1 0 2 0 2...
output:
2558367 2554273
result:
ok single line: '2558367 2554273'
Test #3:
score: 10
Accepted
time: 6ms
memory: 13028kb
input:
579 1522 4047922 2 0 1 2 1 0 1 2 2 2 1 1 1 0 1 1 0 2 0 2 0 2 2 1 2 1 1 0 0 1 0 0 1 0 2 0 1 2 0 0 1 2...
output:
1345823 1354676
result:
ok single line: '1345823 1354676'
Test #4:
score: 10
Accepted
time: 3ms
memory: 13036kb
input:
1085 1454 9313630 1 0 0 1 1 2 0 1 0 0 0 0 0 2 2 0 0 0 2 1 1 1 2 1 2 0 0 1 2 2 1 2 2 0 0 1 1 0 0 1 0 ...
output:
3096226 3107344
result:
ok single line: '3096226 3107344'
Test #5:
score: 10
Accepted
time: 7ms
memory: 13008kb
input:
1242 884 7691408 2 2 0 1 0 2 0 2 2 2 2 1 2 0 0 2 1 0 0 1 2 0 2 2 0 2 0 0 1 1 1 0 1 1 1 2 1 1 0 2 0 2...
output:
2558367 2554273
result:
ok single line: '2558367 2554273'
Test #6:
score: 10
Accepted
time: 0ms
memory: 13028kb
input:
579 1522 4047922 2 0 1 2 1 0 1 2 2 2 1 1 1 0 1 1 0 2 0 2 0 2 2 1 2 1 1 0 0 1 0 0 1 0 2 0 1 2 0 0 1 2...
output:
1345823 1354676
result:
ok single line: '1345823 1354676'
Test #7:
score: 10
Accepted
time: 3ms
memory: 13044kb
input:
2349 1852 73053092665247505 0 1 1 2 0 2 0 2 1 2 2 0 0 2 1 0 1 0 0 1 2 2 0 0 0 1 1 2 0 1 0 2 1 0 0 0 ...
output:
24353986363313222 24352592588219517
result:
ok single line: '24353986363313222 24352592588219517'
Test #8:
score: 10
Accepted
time: 0ms
memory: 13036kb
input:
1843 1745 734716292152659429 1 1 2 0 0 0 1 1 1 1 0 0 1 0 2 1 1 0 1 2 1 2 1 1 0 2 1 1 0 0 2 0 0 2 2 1...
output:
245130077221903396 244734851676961960
result:
ok single line: '245130077221903396 244734851676961960'
Test #9:
score: 10
Accepted
time: 35ms
memory: 18740kb
input:
176 237562 285394849280826820 0 2 1 1 0 1 1 2 0 0 1 2 1 0 2 1 1 0 2 2 0 2 2 0 1 1 2 0 2 1 0 1 2 1 2 ...
output:
95131475359456421 95147338625720373
result:
ok single line: '95131475359456421 95147338625720373'
Test #10:
score: 10
Accepted
time: 93ms
memory: 20728kb
input:
436385 254840 584127032912080903 0 0 0 1 1 0 2 2 2 1 2 0 1 0 1 1 2 1 2 0 1 2 0 1 2 1 2 1 0 2 2 2 0 2...
output:
194709074062540504 194710462993341662
result:
ok single line: '194709074062540504 194710462993341662'