結果
問題 |
No.438 Cwwプログラミング入門
|
ユーザー |
|
提出日時 | 2020-03-05 05:39:40 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,655 bytes |
コンパイル時間 | 665 ms |
コンパイル使用メモリ | 66,156 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-14 00:41:15 |
合計ジャッジ時間 | 5,647 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 84 WA * 14 |
コンパイルメッセージ
main.cpp:17:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 17 | 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; } 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; if(k>0&&l<0) { long kt=k/y; long lt=-l/x; long t=kt<lt?kt:lt; k-=y*t; l+=x*t; } if(k<0&&l>0) { long kt=-k/y; long lt=l/x; long t=kt<lt?kt:lt; k+=y*t; l-=x*t; } string ans=""; if(k==0) { if(l+l-1>10000) { cout<<"NO"<<endl; return 0; } else { for(int i=0;i<l;i++) { ans+='w'; if(i)ans+='C'; } } } else if(l==0) { if(k+k-1>10000) { cout<<"NO"<<endl; return 0; } 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) { cout<<"NO"<<endl; return 0; } 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) { cout<<"NO"<<endl; return 0; } 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'; } } } cout<<ans<<endl; }