結果

問題 No.2715 Unique Chimatagram
ユーザー Shreyan RayShreyan Ray
提出日時 2024-04-05 22:18:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 2,001 bytes
コンパイル時間 3,267 ms
コンパイル使用メモリ 212,996 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-05 22:18:44
合計ジャッジ時間 4,008 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 3 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 3 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 3 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 2 ms
6,676 KB
testcase_28 AC 3 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 3 ms
6,676 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 2 ms
6,676 KB
testcase_33 AC 2 ms
6,676 KB
testcase_34 AC 2 ms
6,676 KB
testcase_35 AC 2 ms
6,676 KB
testcase_36 AC 2 ms
6,676 KB
testcase_37 AC 2 ms
6,676 KB
testcase_38 AC 2 ms
6,676 KB
testcase_39 AC 21 ms
6,676 KB
testcase_40 AC 3 ms
6,676 KB
testcase_41 AC 10 ms
6,676 KB
testcase_42 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (int)1e18
#define f first
#define s second

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

void Solve() 
{
    int n; cin >> n;
    
    vector<string> a(n);
    for (auto &x : a){
        cin >> x;
        sort(x.begin(), x.end());
    }
    
    for (int i = 0; i < n; i++){
        vector <int> c1(26, 0);
        for (auto ch : a[i]) c1[ch - 'a']++;
        
        bool good = true;
        vector<bool> poss(26, true);
        int count = 0;
        for (auto x : a){
            count++;
            if (x.size() != a[i].size()) continue;
            if (count == i + 1) continue;
            
            if (x == a[i]) {
                good = false;
                break;
            }
            
            vector <int> c2(26, 0);
            for (auto ch : x) c2[ch - 'a']++;
            
            int diff = 0;
            for (int i = 0; i < 26; i++) diff += abs(c2[i] - c1[i]);
            
            if (diff == 2){
                for (int i = 0; i < 26; i++) if (c2[i] > c1[i]) poss[i] = false;
            }
        }
        
        if (!good) continue;
        
        for (int j = 0; j < 26; j++){
            if (poss[j]){
                a[i] += (char)(j + 'a');
                cout << a[i] << "\n";
                return;
            }
        }
    }
    
    cout << -1 << "\n";
}

int32_t main() 
{
    auto begin = std::chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // freopen("in",  "r", stdin);
    // freopen("out", "w", stdout);
    
   // cin >> t;
    for(int i = 1; i <= t; i++) 
    {
        //cout << "Case #" << i << ": ";
        Solve();
    }
    auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
    return 0;
}
0