結果

問題 No.438 Cwwプログラミング入門
ユーザー Bantako
提出日時 2017-08-23 22:07:43
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,474 bytes
コンパイル時間 1,643 ms
コンパイル使用メモリ 170,900 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-15 13:34:37
合計ジャッジ時間 9,799 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 69 WA * 20 RE * 9
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 % gcd(x,y)){
        cout << "NO" << endl;
        return 0;
    }
    ll min = INF;
    pair<ll,ll> ans = make_pair(INF,INF);
    for(ll i = -100;i < 100;i++){
        for(ll j = -100;j < 100;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 < b || b == 0){
        if(a == 0){        
            str += string(llabs(b),'w') + string(llabs(b)-1,'C');
            goto print;
        }
        str += string(llabs(a),'c') + string(llabs(a)-1,'C');
        str += string(llabs(b),'w') + string(llabs(b)-1,'C');
        str += (a<0?"W":"C");
    }else{
        if(a == 0){        
            str += string(llabs(a),'c') + string(llabs(a)-1,'C');
            goto print;
        }
        str += string(llabs(b),'w') + string(llabs(b)-1,'C');
        str += string(llabs(a),'c') + string(llabs(a)-1,'C');
        str += (b<0?"W":"C");
    }
    print:
    if(str.length() > 10000)cout << "NO" << endl;
    else cout << str << endl;
}       
0