結果

問題 No.438 Cwwプログラミング入門
ユーザー bal4ubal4u
提出日時 2019-06-27 13:54:58
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,841 bytes
コンパイル時間 1,052 ms
コンパイル使用メモリ 30,760 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-10 05:25:01
合計ジャッジ時間 7,007 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,380 KB
testcase_01 AC 0 ms
4,384 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 0 ms
4,384 KB
testcase_06 AC 0 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 0 ms
4,380 KB
testcase_09 AC 0 ms
4,376 KB
testcase_10 AC 0 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 0 ms
4,376 KB
testcase_13 AC 0 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 0 ms
4,380 KB
testcase_19 AC 0 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,384 KB
testcase_22 AC 0 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,384 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 0 ms
4,384 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 AC 0 ms
4,380 KB
testcase_46 AC 0 ms
4,380 KB
testcase_47 AC 1 ms
4,376 KB
testcase_48 AC 1 ms
4,380 KB
testcase_49 AC 0 ms
4,380 KB
testcase_50 AC 0 ms
4,380 KB
testcase_51 AC 0 ms
4,380 KB
testcase_52 AC 1 ms
4,380 KB
testcase_53 AC 1 ms
4,376 KB
testcase_54 AC 0 ms
4,380 KB
testcase_55 AC 1 ms
4,384 KB
testcase_56 AC 1 ms
4,384 KB
testcase_57 AC 0 ms
4,380 KB
testcase_58 AC 0 ms
4,376 KB
testcase_59 AC 1 ms
4,376 KB
testcase_60 AC 0 ms
4,376 KB
testcase_61 AC 1 ms
4,380 KB
testcase_62 AC 1 ms
4,380 KB
testcase_63 AC 0 ms
4,376 KB
testcase_64 AC 1 ms
4,380 KB
testcase_65 AC 1 ms
4,380 KB
testcase_66 AC 0 ms
4,384 KB
testcase_67 AC 0 ms
4,384 KB
testcase_68 AC 1 ms
4,380 KB
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 AC 1 ms
4,380 KB
testcase_74 WA -
testcase_75 WA -
testcase_76 AC 1 ms
4,380 KB
testcase_77 AC 0 ms
4,380 KB
testcase_78 AC 0 ms
4,376 KB
testcase_79 AC 1 ms
4,380 KB
testcase_80 AC 0 ms
4,380 KB
testcase_81 AC 1 ms
4,380 KB
testcase_82 AC 0 ms
4,376 KB
testcase_83 AC 0 ms
4,380 KB
testcase_84 AC 1 ms
4,376 KB
testcase_85 AC 1 ms
4,384 KB
testcase_86 AC 1 ms
4,380 KB
testcase_87 AC 1 ms
4,376 KB
testcase_88 AC 1 ms
4,380 KB
testcase_89 AC 0 ms
4,376 KB
testcase_90 AC 1 ms
4,384 KB
testcase_91 AC 0 ms
4,384 KB
testcase_92 AC 1 ms
4,380 KB
testcase_93 AC 0 ms
4,376 KB
testcase_94 AC 0 ms
4,380 KB
testcase_95 AC 1 ms
4,376 KB
testcase_96 AC 0 ms
4,380 KB
testcase_97 AC 1 ms
4,380 KB
testcase_98 AC 1 ms
4,380 KB
testcase_99 AC 1 ms
4,380 KB
testcase_100 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:9:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    9 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:17:24: 備考: in expansion of macro ‘gc’
   17 |         int n = 0, c = gc();
      |                        ^~
main.c: 関数 ‘pcs’ 内:
main.c:10:15: 警告: 関数 ‘putchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   10 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:23:39: 備考: in expansion of macro ‘pc’
   23 | void pcs(int n, char c) { while (n--) pc(c); }
      |                                       ^~

ソースコード

diff #

// yukicoder: No.438 Cwwプログラミング入門
// 2019.6.27 bal4u

#include <stdio.h>

typedef long long ll;

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()    // 非負整数の入力
{
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

#define ABS(x)  ((x)>=0?(x):-(x))
void pcs(int n, char c) { while (n--) pc(c); }
void outs(char *s) { while (*s) pc(*s++); pc('\n'); }
int extended_gcd(int a, int b, int *x, int *y) {
	int d;
	if (b == 0) { *x = 1; *y = 0; return a; }
	d = extended_gcd(b, a%b, y, x);
	*y -= a / b * (*x);
	return d;
}

int x, y, z;
int a, b, d;
ll X, Y;

ll calc(int s) {
	X = (z/d)*(ll)a - (y/d)*(ll)s;
	Y = (z/d)*(ll)b + (x/d)*(ll)s;
	return ABS(X) + ABS(Y);
}

int findMin(int l, int r) {
	int m;
	while (r-l > 1) {
		m = (l + r) >> 1;
		if (calc(m) - calc(m-1) < 0) l = m;
		else r = m;
	}
	return l;
}

int main()
{
	int s;

	x = in(), y = in(), z = in();
	if (x == 0 && y == 0) {
		if (z == 0) { outs("ccC"); return 0; }
		goto err;
	}
	if (x == 0) {
		if (z % y == 0 && z / y <= 5000) {
			pcs(z/y, 'w'), pcs(z/y-1, 'C'), pc('\n');
			return 0;
		}
		goto err;
	}
	if (y == 0 || x == y) {
		if (z % x == 0 && z / x <= 5000) {
			pcs(z/x, 'c'), pcs(z/x-1, 'C'), pc('\n');
			return 0;
		}
		goto err;
	}
	if (z == 0) { outs("ccW"); return 0; }

	d = extended_gcd(x, y, &a, &b);
	if (z % d) goto err;
		
	s = findMin(-100005, 100005);
	if (calc(s) > 5000) goto err;
	x = (int)X, y = (int)Y;

	if (x < 0) {
		x = -x;
		pcs(x, 'c'), pcs(y, 'w');
		pcs(y-1, 'C'), pcs(x, 'W');
	} else if (y < 0) {
		y = -y;
		pcs(y, 'w'), pcs(x, 'c');
		pcs(x-1, 'C'), pcs(y, 'W');
	} else {
		pcs(x, 'c'), pcs(y, 'w');
		pcs(x+y-1, 'C');
	}
	pc('\n');
	return 0;
err: outs("NO");
	return 0;
}
0