結果

問題 No.2745 String Swap Battle
ユーザー eve__fuyukieve__fuyuki
提出日時 2024-04-20 13:52:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,238 bytes
コンパイル時間 2,083 ms
コンパイル使用メモリ 201,932 KB
実行使用メモリ 8,448 KB
最終ジャッジ日時 2024-04-20 13:53:09
合計ジャッジ時間 3,197 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
7,976 KB
testcase_01 AC 29 ms
7,980 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 50 ms
8,448 KB
testcase_07 AC 66 ms
8,448 KB
testcase_08 AC 50 ms
8,320 KB
testcase_09 AC 44 ms
8,064 KB
testcase_10 AC 22 ms
6,940 KB
testcase_11 AC 12 ms
6,940 KB
testcase_12 AC 13 ms
6,940 KB
testcase_13 AC 13 ms
6,948 KB
testcase_14 AC 13 ms
6,940 KB
testcase_15 AC 19 ms
6,944 KB
testcase_16 AC 19 ms
6,944 KB
testcase_17 AC 19 ms
6,940 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:30:25: warning: 'a' may be used uninitialized [-Wmaybe-uninitialized]
   30 |         while (s[i][ii] != a) {
main.cpp:20:14: note: 'a' was declared here
   20 |         char a, b;
      |              ^
main.cpp:33:25: warning: 'b' may be used uninitialized [-Wmaybe-uninitialized]
   33 |         while (s[i][jj] != b) {
main.cpp:20:17: note: 'b' was declared here
   20 |         char a, b;
      |                 ^

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}
int main() {
    fast_io();
    int n;
    cin >> n;
    vector<string> s(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        if (is_sorted(s[i].begin(), s[i].end())) {
            swap(s[i][s[i].size() - 1], s[i][s[i].size() - 2]);
            continue;
        }
        multiset<char> st(s[i].begin(), s[i].end());
        char a, b;
        for (int j = 0; j < s[i].size(); j++) {
            if (s[i][j] != *st.begin()) {
                a = s[i][j];
                b = *st.begin();
                break;
            }
            st.erase(st.begin());
        }
        int ii = 0, jj = s[i].size() - 1;
        while (s[i][ii] != a) {
            ii++;
        }
        while (s[i][jj] != b) {
            jj--;
        }
        swap(s[i][ii], s[i][jj]);
    }
    string mi = *min_element(s.begin(), s.end());
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == mi) {
            cnt++;
        }
    }
    for (int i = 0; i < n; i++) {
        if (s[i] == mi) {
            cout << n - cnt + 1 << "\n";
        } else {
            cout << "0\n";
        }
    }
}
0