結果
問題 |
No.438 Cwwプログラミング入門
|
ユーザー |
![]() |
提出日時 | 2016-10-28 23:59:30 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,115 bytes |
コンパイル時間 | 3,809 ms |
コンパイル使用メモリ | 99,400 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-24 21:35:16 |
合計ジャッジ時間 | 7,603 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 96 WA * 2 |
ソースコード
#define _CRT_SECURE_NO_WARNINGS #include<sstream> #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<climits> #include<cmath> #include<string> #include<vector> #include<set> #include<map> #include<queue> #include<numeric> #include<functional> #include<algorithm> #include<bitset> #include<tuple> #include<unordered_set> #include<random> using namespace std; #define INF (1<<29) #define rep(i,n) for(int i=0;i<(int)(n);i++) #define all(v) v.begin(),v.end() #define uniq(v) v.erase(unique(all(v)),v.end()) long long run(int x,int y,string s) { long long st[5001]; int p = 0; for (char c : s) { if (c == 'c') { st[p++] = x; } else if (c == 'w') { st[p++] = y; } else if (c == 'C') { st[p - 2] = st[p - 1] + st[p - 2]; p --; } else { st[p - 2] = st[p - 1] - st[p - 2]; p --; } } return st[0]; } int main() { ios::sync_with_stdio(0); cin.tie(0); long long x, y, z; cin >> x >> y >> z; for (int i = -5000; i <= 5000;i++) { for (int j = -5000 + abs(i); j <= 5000 - abs(i); j++) { if (x*i + y*j == z) { if (i == 0 && j == 0) { continue; } int n = (abs(i) + abs(j)) * 2; if (i > 0 || j > 0)n--; else n += 3; if (n > 10000)continue; string num, op; if (i > 0) { num+= 'c'; rep(_, i - 1) { num += 'c'; op += 'C'; } if (j > 0) { rep(_, j) { num += 'w'; op += 'C'; } } else { rep(_, -j) { num += 'w'; op += 'W'; } } } else if (j > 0) { num += 'w'; rep(_, j - 1) { num += 'w'; op += 'C'; } rep(_, -i) { num += 'c'; op += 'W'; } } else { num += 'c'; num += 'c'; op += 'W'; rep(_, -i) { num += 'c'; op += 'W'; } rep(_, -j) { num += 'w'; op += 'W'; } } reverse(all(num)); //cout << run(x, y, num + op)<<endl; if (run(x, y, num + op) == z) { cout << num << op << endl; return 0; } } } } cout << "mourennaihasimasenn" << endl; return 0; }