結果
問題 | No.2226 Hello, Forgotten World! |
ユーザー | milanis48663220 |
提出日時 | 2023-02-24 21:32:23 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 9 ms / 2,000 ms |
コード長 | 2,079 bytes |
コンパイル時間 | 1,115 ms |
コンパイル使用メモリ | 119,080 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-13 05:07:20 |
合計ジャッジ時間 | 1,682 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 9 |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <cmath> #include <numeric> #include <functional> #include <cassert> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template<typename T> vector<vector<T>> vec2d(int n, int m, T v){ return vector<vector<T>>(n, vector<T>(m, v)); } template<typename T> vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){ return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v))); } template<typename T> void print_vector(vector<T> v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } const string helloworld = "helloworld"; bool ok(string s){ for(int i = 0; i < helloworld.size(); i++){ if(s[i] == '?') continue; if(s[i] != helloworld[i]) return false; } return true; } void solve(){ int n; cin >> n; string s; cin >> s; string ans = "-1"; int len = helloworld.size(); for(int i = 0; i+len <= n; i++){ if(ok(s.substr(i, len))){ string t = s; for(int j = i; j < i+len; j++) t[j] = helloworld[j-i]; for(int j = 0; j < n; j++){ if(t[j] == '?') t[j] = 'a'; } if(ans == "-1"){ ans = t; }else{ chmin(ans, t); } } } cout << ans << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int t; cin >> t; while(t--) solve(); }