結果
| 問題 |
No.438 Cwwプログラミング入門
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-03-05 05:35:37 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,455 bytes |
| コンパイル時間 | 540 ms |
| コンパイル使用メモリ | 66,408 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-19 16:29:18 |
| 合計ジャッジ時間 | 9,828 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 50 WA * 48 |
コンパイルメッセージ
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;
x/=g;
y/=g;
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
{
for(int i=0;i<k;i++)
{
ans+='c';
if(i)ans+='C';
}
for(int i=l<0?-l:l;i--;)
{
ans+='w';
ans+=l<0?'W':'C';
}
}
}
else
{
if(l+l-1-k*2>10000)
{
cout<<"NO"<<endl;
return 0;
}
else
{
for(int i=0;i<l;i++)
{
ans+='w';
if(i)ans+='C';
}
for(int i=-k;i--;)
{
ans+='c';
ans+='W';
}
}
}
cout<<ans<<endl;
}