結果

問題 No.438 Cwwプログラミング入門
ユーザー tossy
提出日時 2016-10-29 11:54:38
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,868 bytes
コンパイル時間 1,083 ms
コンパイル使用メモリ 103,412 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-24 23:06:51
合計ジャッジ時間 8,333 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 63 WA * 34 RE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<(x)<<endl
#define fi first
#define se second

#define INF 2147483600


// a*x + b*y = gcd(a, b)
int extgcd(int a, int b, int& x, int& y){
  int d=a;
  if(b!=0){
    d=extgcd(b, a%b, y, x);
    y-=(a/b)*x;
  } else {
    x=1; y=0;
  }
  return d;
}

bool solve(){
  int x,y,z;
  cin>>x>>y>>z;

  int a,b;
  int g = extgcd(x, y, a, b);
  // ax + by = g

  if(z==0){
    if(x==y){cout<<"cwW"<<endl;return true;}
    if(x==0){cout<<"c"<<endl; return true;}
    if(y==0){cout<<"w"<<endl; return true;}
    else return false;
  }

  if(z%g!=0 || (a==0 && b==0)){
    return false;
  }

  string push="", pop="";
  bool flg=false;
  string xx="c", yy="w";
  if(x<y){ swap(x,y); swap(xx,yy); }
  if(x!=0 && z > x/2){
    if(z/x > 5010) return false;
    rep(i, z/x){
      push += xx;
      pop += "C";
    }
    z = z%x;
    if(z > x/2){
      push += xx;
      pop += "C";
      z -= x;
    }
    flg=true;
  }
  if(y!=0 && abs(z) > y/2){
    if(pop.size() + abs(z)/y > 5010) return false;
    if(z>0){
      rep(i, z/y){
        push += yy;
        pop += "C";
      }
      z = z%y;
      if(z > y/2){
        push += yy;
        pop += "C";
        z += y;
      }
    }
    if(z<0){
      rep(i, abs(z)/y){
        push = yy + push;
        pop += "W";
      }
      z += abs(z)/y * y;
      if(abs(z) > y/2){
        push = yy + push;
        pop += "W";
        z += x;
      }
    }
    flg=true;
  }
  if(z==0){
    if(push.size() + pop.size()-1 > 10000) return false;
    cout<<push<<pop.substr(1)<<endl;
    return true;
  }
  string res;
  if(flg) res = push + pop.substr(1);

  if(res.size() + z/g*2*abs(a+b) > 10050) return false;

  push="";pop="";
  if(a<0){
    rep(i,-a) push += "c";
    rep(i,-a) pop = "W" + pop;
  }
  if(b<0){
    rep(i,-b) push += "w";
    rep(i,-b) pop = "W" + pop;
  }
  if(a>0){
    rep(i,a) push += "c";
    rep(i,a) pop = "C"+pop;
  }
  if(b>0){
    rep(i,b) push += "w";
    rep(i,b) pop = "C"+pop;
  }
  pop = pop.substr(1);

  if(z>0){
    rep(i,abs(z)/g){
      res += push + pop;
      if(i!=0) res += "C";
    }
    if(flg) res += "C";
  }
  if(z<0){
    string tmp="";
    rep(i,abs(z)/g){
      tmp += push + pop;
      if(i==0) pop += "C";
    }
    res = tmp + res + "W";
  }


  if(res.size()>10000) return false;
  else cout<<res<<endl;
  return true;
}

int main(){
  if(!solve()) cout<<"mourennaihasimasenn"<<endl;

  return 0;
}
0