結果
| 問題 | No.501 穴と文字列 |
| コンテスト | |
| ユーザー |
startcpp
|
| 提出日時 | 2016-07-10 18:36:39 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 584 bytes |
| コンパイル時間 | 487 ms |
| コンパイル使用メモリ | 57,592 KB |
| 実行使用メモリ | 815,360 KB |
| 最終ジャッジ日時 | 2024-10-13 10:28:02 |
| 合計ジャッジ時間 | 3,919 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | MLE * 1 -- * 21 |
ソースコード
//3^N通りの文字列を作成する
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int n, d;
string best;
void dfs(string s) {
if (s.length() == n) {
int num = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'A') num += 1;
if (s[i] == 'B') num += 2;
if (s[i] == 'C') num += 0;
}
if (num == d) {
//更新
if (best.length() == 0 || strcmp(s.c_str(), best.c_str()) < 0) {
best = s;
}
}
return;
}
dfs(s + 'A');
dfs(s + 'B');
dfs(s + 'C');
}
int main() {
cin >> n >> d;
dfs("");
cout << best << endl;
return 0;
}
startcpp