結果
| 問題 | No.438 Cwwプログラミング入門 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-10-29 00:04:00 |
| 言語 | C++11 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,386 bytes |
| 記録 | |
| コンパイル時間 | 1,215 ms |
| コンパイル使用メモリ | 181,008 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-05-19 01:59:22 |
| 合計ジャッジ時間 | 49,800 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 47 WA * 49 RE * 2 |
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/cstdlib:87,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/x86_64-pc-linux-gnu/bits/stdc++.h:41,
from main.cpp:1:
In function 'long long int std::abs(long long int)',
inlined from 'int main()' at main.cpp:52:10:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/std_abs.h:67:51: warning: 'A' may be used uninitialized [-Wmaybe-uninitialized]
67 | abs(long long __x) { return __builtin_llabs (__x); }
| ^
main.cpp: In function 'int main()':
main.cpp:44:19: note: 'A' was declared here
44 | long long A, B;
| ^
In function 'long long int std::abs(long long int)',
inlined from 'int main()' at main.cpp:52:19:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/std_abs.h:67:51: warning: 'B' may be used uninitialized [-Wmaybe-uninitialized]
67 | abs(long long __x) { return __builtin_llabs (__x); }
| ^
main.cpp: In function 'int main()':
main.cpp:44:22: note: 'B' was declared here
44 | long long A, B;
| ^
ソースコード
#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> extgcd(long long a, long long b, long long c) {
if (b == 0) return make_pair(c, 0);
long long x, y;
tie(x, y) = extgcd(b, a % b, c);
return make_pair(y, x - a / b * y);
}
int gcd(int x, int y) {
if (y == 0) return x;
return gcd(y, x % y);
}
string create(int x, char c) {
if (x >= 10100) x = 10100;
string s(1, c);
for (int i = 0; i < x - 1; i++) {
s += c;
s += "C";
}
return s;
}
int main() {
int x, y, z;
cin >> x >> y >> z;
int g = gcd(x, y);
if (z % g != 0) {
cout << "mourennaihasimasenn" << endl;
return 0;
}
x /= g;
y /= g;
z /= g;
long long a, b;
tie(a, b) = extgcd(x, y, z);
long long A, B;
const int N = 1e8;
a -= y * N;
b += x * N;
for (long long i = 0; i <= 2 * N; i++) {
if (abs(A) + abs(B) > abs(a) + abs(b)) {
A = a;
B = b;
}
a += y;
b -= x;
}
cerr << A << " " << B << endl;
string ans;
if (B == 0) {
ans = create(abs(A), 'c');
} else if (A == 0) {
ans = create(abs(B), 'w');
} else if (A > 0 && B > 0) {
ans = create(abs(A), 'c') + create(abs(B), 'w') + "C";
} else if (A < 0) {
ans = create(abs(B), 'w') + create(abs(A), 'c') + "W";
} else if (B < 0) {
ans = create(abs(A), 'c') + create(abs(B), 'w') + "W";
}
if (ans.size() > 10000) {
cout << "mourennaihasimasenn" << endl;
} else {
cout << ans << endl;
}
}