結果

問題 No.438 Cwwプログラミング入門
ユーザー Bantako
提出日時 2017-08-23 22:30:32
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 1,362 bytes
コンパイル時間 1,578 ms
コンパイル使用メモリ 172,380 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-15 13:38:49
合計ジャッジ時間 8,003 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 98
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:10:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   10 | main(){
      | ^~~~

ソースコード

diff #

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1e9;
int MOD = 1e9+7;
ll gcd (ll a,ll b){
    if(!b)return a;
    return gcd(b,a%b);
}
main(){
    ll x,y,z;
    cin >> x >> y >> z;
    if(z && (!(x|y) || z % gcd(x,y))){
        cout << "NO" << endl;
        return 0;
    }
    ll min = INF;
    pair<ll,ll> ans = make_pair(INF,INF);
    for(ll i = -5000;i <= 5000;i++){
        for(ll j = -5000;j <= 5000;j++){
            if(x*i + y*j == z)if(llabs(i)+llabs(j) < min){
                min = llabs(i)+llabs(j);
                ans = make_pair(i,j);
            }
        }
    }
    ll a = ans.first,b = ans.second;
//    cout << a << " " << b << endl;
    if(llabs(a)*2+llabs(b)*2 > 20000){
        cout << "NO" << endl;
        return 0;
    }
    string str;
    if(a == 0 & b == 0){
        str = "ccW";
    }else if(a < b || b == 0){
        if(a != 0)str += string(llabs(a),'c') + string(llabs(a)-1,'C');
        if(b != 0)str += string(llabs(b),'w') + string(llabs(b)-1,'C');
        if(a != 0 && b != 0)str += (a<0?"W":"C");
    }else{
        if(b != 0)str += string(llabs(b),'w') + string(llabs(b)-1,'C');
        if(a != 0)str += string(llabs(a),'c') + string(llabs(a)-1,'C');
        if(a != 0 && b != 0)str += (b<0?"W":"C");
    }
    if(str.length() > 10000)cout << "NO" << endl;
    else cout << str << endl;
}       
0