結果
| 問題 | No.3587 Too Good to Swap |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-05-26 13:34:46 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,012 bytes |
| 記録 | |
| コンパイル時間 | 418 ms |
| コンパイル使用メモリ | 97,044 KB |
| 実行使用メモリ | 9,420 KB |
| 最終ジャッジ日時 | 2026-07-10 20:53:15 |
| 合計ジャッジ時間 | 2,375 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | AC * 6 WA * 43 |
ソースコード
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
// 文字列から 'o' を除いた骨格 (相対順序) を取得する関数
string get_core(const string& s) {
string core = "";
for (char c : s) {
if (c != 'o') core += c;
}
return core;
}
// 「局所的な壁」が存在するか判定する嘘関数
bool has_local_wall(const string& s) {
bool in_g = false;
int o_count = 0;
for (char c : s) {
if (c == 'g') {
in_g = true;
o_count = 0; // 新しい g が来たらリセット
} else if (c == 'o') {
if (in_g) o_count++;
} else if (c == 'd') {
// g の後に o が3つ以上続いて d が来た場合、壁とみなす
if (in_g && o_count >= 3) {
return true;
}
in_g = false;
}
}
return false;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N;
if (!(cin >> N)) return 0;
string S, T;
cin >> S >> T;
// 1. 各文字の出現回数が一致するかチェック
int cS[3] = {0}, cT[3] = {0};
for(char c : S) {
if(c == 'd') cS[0]++; else if(c == 'o') cS[1]++; else cS[2]++;
}
for(char c : T) {
if(c == 'd') cT[0]++; else if(c == 'o') cT[1]++; else cT[2]++;
}
for(int i = 0; i < 3; i++) {
if(cS[i] != cT[i]) {
cout << "No\n";
return 0;
}
}
// 2. 嘘判定:局所的な壁の評価
bool s_wall = has_local_wall(S);
bool t_wall = has_local_wall(T);
// どちらかに壁がある場合、相対順序は絶対に変わらないと誤認する
if (s_wall || t_wall) {
if (get_core(S) == get_core(T)) {
cout << "Yes\n";
} else {
cout << "No\n";
}
} else {
// 壁がない場合は自由に交差可能とみなす
cout << "Yes\n";
}
return 0;
}