結果

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

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 438.cc: No.438 Cwwプログラミング入門 - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_L = 10000;

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

void putchars(int m, int c) {
  for (int i = 0; i < m; i++) putchar(c);
}

/* main */

int main() {
  int x, y, z;
  cin >> x >> y >> z;

  // z==0 -> x-x=0
  if (z == 0) {
    puts("ccW");
    return 0;
  }

  if (x > 0 && z >= x && z % x == 0) {
    int a = z / x;
    if (2 * a - 1 <= MAX_L) {
      putchars(a, 'c');
      putchars(a - 1, 'C');
      putchar('\n');
      return 0;
    }
  }
  if (y == 0) {
    puts("NO");
    return 0;
  }

  if (y > 0 && z >= y && z % y == 0) {
    int b = z / y;
    if (2 * b - 1 <= MAX_L) {
      putchars(b, 'w');
      putchars(b - 1, 'C');
      putchar('\n');
      return 0;
    }
  }
  if (x == 0) {
    puts("NO");
    return 0;
  }

  // ax + by = z -> by = z - ax
  for (ll aa = 0; aa <= MAX_L / 2; aa++) {
    ll as[2] = {-aa, aa};
    for (int i = 0; i < 2; i++) {
      ll &a = as[i];
      ll by = z - a * x;
      if (by % y == 0) {
	ll b = by / y;
	//printf("a=%lld,b=%lld\n", a, b);
	if ((abs(a) + abs(b)) * 2 - 1 <= MAX_L) {
	  if (b < 0) {
	    b = -b;
	    putchars(b, 'w');
	    putchars(b - 1, 'C');
	    putchars(a, 'c');
	    putchars(a - 1, 'C');
	    putchar('W');
	    putchar('\n');
	  }
	  else if (a < 0) {
	    a = -a;
	    putchars(a, 'c');
	    putchars(a - 1, 'C');
	    putchars(b, 'w');
	    putchars(b - 1, 'C');
	    putchar('W');
	    putchar('\n');
	  }
	  else {
	    putchars(a, 'c');
	    putchars(a - 1, 'C');
	    putchars(b, 'w');
	    putchars(b - 1, 'C');
	    putchar('C');
	    putchar('\n');
	  }
	  return 0;
	}
      }
    }
  }

  puts("NO");
  return 0;
}
0