結果

問題 No.438 Cwwプログラミング入門
ユーザー tossytossy
提出日時 2016-10-29 12:31:48
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,811 bytes
コンパイル時間 857 ms
コンパイル使用メモリ 92,348 KB
実行使用メモリ 13,640 KB
最終ジャッジ日時 2024-11-24 23:07:30
合計ジャッジ時間 32,249 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 56 WA * 35 RE * 1 OLE * 6
権限があれば一括ダウンロードができます

ソースコード

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;

  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;
  }

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

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

  char xx='c', yy='w';
  if(y>x){ swap(x,y); swap(a,b); swap(xx,yy); }
  int nx=0, ny=0;

  nx = z/x;
  z %= x;
  if(z > x/2){
    nx++;
    z -= x;
  }

  if(z>0){
    nx += a * z/g;
    ny += b * z/g;
  } else {
    nx -= a * z/g;
    ny -= b * z/g;
  }

  if((abs(nx)+abs(ny))*2-1>10000) return false;

  int p=-1,m=0;
  if(nx<0){
    rep(i,-nx) printf("%c", xx);
    m += -nx;
  }
  if(ny<0){
    rep(i,-ny) printf("%c", yy);
    m += -ny;
  }
  if(nx>0){
    rep(i, nx) printf("%c", xx);
    p += nx;
  }
  if(ny>0){
    rep(i, ny) printf("%c", yy);
    p += ny;
  }
  rep(i, p) printf("%c", 'C');
  rep(i, m) printf("%c", 'W');
  printf("\n");
  return true;
}

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

  return 0;
}
0