結果

問題 No.438 Cwwプログラミング入門
ユーザー kitayankitayan
提出日時 2016-11-08 15:43:44
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,244 bytes
コンパイル時間 724 ms
コンパイル使用メモリ 55,772 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-27 22:17:34
合計ジャッジ時間 4,363 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 98
権限があれば一括ダウンロードができます

ソースコード

diff #

//
//  438.cpp
//  yukicoder
//
//  Created by KITAZUMI on 2016/11/08.
//  Copyright © 2016年 KITAZUMI. All rights reserved.
//

#include<iostream>
#include<cstdlib>

using namespace std;

int main(){
    long a, b, x, y, z;
    long amari;
    cin >> x >> y >> z;
    
    if(z == 0){
        cout << "ccW" << endl;
return 0;
    }
    
    if(x == 0 && y == 0){
        if(z == 0){
            cout << "ccC" << endl;
            return 0;
        }
        else{
            cout << "NO" << endl;
            return 0;
        }
    }
    else if(x != 0){
        for(b = 0; b <= 5000; b++){
            amari = (z - b * y) % x;
            a = (z - b * y) / x;
            if(amari == 0){
                if(2*abs(a)+2*abs(b)-1 <= 10000){
                    break;
                }
            }
            amari = (z + b * y) % x;
            a = (z + b * y) / x;
            if(amari == 0){
                if(2*abs(a)+2*abs(b)-1 <= 10000){
                    b = -b;
                    break;
                }
            }
        }
    }else{
        if(z % y != 0){
            cout << "NO" << endl;
            return 0;
        }
        else{
            b = z / y;
            a = 0;
        }
    }
    if(2*abs(a)+2*abs(b)-1 > 10000){
        cout << "NO" << endl;
        return 0;
    }
    if(a >= 0 && b >= 0){
        for(int i = 0; i < a; i++){
            cout << "c";
        }
        for(int i = 0; i < b; i++){
            cout << "w";
        }
        for(int i = 0; i < a+b-1; i++){
            cout << "C";
        }
    }
    else if(a < 0 && b >= 0){
        for(int i = 0 ; i < -a; i++){
            cout << "c";
        }
        for(int i = 0; i < b; i++){
            cout << "w";
        }
        for(int i = 0; i < b-1; i++){
            cout << "C";
        }
        for(int i = 0; i < -a; i++){
            cout << "W";
        }
    }
    else if(a >= 0 && b < 0){
        for(int i = 0; i < -b; i++){
            cout << "w";
        }
        for(int i = 0; i < a; i++){
            cout << "c";
        }
        for(int i = 0; i < a-1; i++){
            cout << "C";
        }
        for(int i = 0; i < -b; i++){
            cout << "W";
        }
    }
    cout << endl;
    return 0;
}
0