結果
問題 | No.438 Cwwプログラミング入門 |
ユーザー |
|
提出日時 | 2020-03-05 05:50:50 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 2,048 bytes |
コンパイル時間 | 841 ms |
コンパイル使用メモリ | 68,428 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-14 00:41:26 |
合計ジャッジ時間 | 4,407 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 98 |
コンパイルメッセージ
main.cpp:111:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 111 | main() | ^~~~
ソースコード
#include<iostream> using namespace std; template<typename T> T extgcd(T a,T b,T&x,T&y) { if(b==0) { x=1; y=0; return a; } T q=a/b; T g=extgcd(b,a-q*b,y,x); y-=q*x; return g; } string calc(long k,long l) { string ans=""; if(k==0) { if(l+l-1>10000) { return"NO"; } else { for(int i=0;i<l;i++) { ans+='w'; if(i)ans+='C'; } } } else if(l==0) { if(k+k-1>10000) { return"NO"; } else { for(int i=0;i<k;i++) { ans+='c'; if(i)ans+='C'; } } } else if(k>0) { if(k+k-1+(l<0?-l:l)*2>10000) { return"NO"; } else if(l>0) { for(int i=0;i<k;i++) { ans+='c'; if(i)ans+='C'; } for(int i=0;i<l;i++) { ans+='w'; ans+='C'; } } else { for(int i=0;i<-l;i++) { ans+='w'; } for(int i=0;i<k;i++) { ans+='c'; if(i)ans+='C'; } for(int i=0;i<-l;i++) { ans+='W'; } } } else { if(l+l-1-k*2>10000) { return"NO"; } else { for(int i=0;i<-k;i++) { ans+='c'; } for(int i=0;i<l;i++) { ans+='w'; if(i)ans+='C'; } for(int i=0;i<-k;i++) { ans+='W'; } } } return ans; } main() { long x,y,z;cin>>x>>y>>z; if(z==0) { cout<<"ccW"<<endl; return 0; } if(x==0&&y==0) { cout<<"NO"<<endl; return 0; } long g,k,l; g=extgcd(x,y,k,l); if(z%g!=0) { cout<<"NO"<<endl; return 0; } z/=g; k*=z; l*=z; x/=g; y/=g; string ans=""; if(x<y) { if(k>=0) { long t=k/y; k-=t*y; l+=t*x; ans=calc(k,l); if(ans=="NO") { k-=y; l+=x; ans=calc(k,l); } } else { long t=-k/y; k+=t*y; l-=t*x; ans=calc(k,l); if(ans=="NO") { k+=y; l-=x; ans=calc(k,l); } } } else { if(l>=0) { long t=l/x; k+=t*y; l-=t*x; ans=calc(k,l); if(ans=="NO") { k+=y; l-=x; ans=calc(k,l); } } else { long t=-l/x; k-=t*y; l+=t*x; ans=calc(k,l); if(ans=="NO") { k-=y; l+=x; ans=calc(k,l); } } } cout<<ans<<endl; }