結果

問題 No.832 麻雀修行中
ユーザー veqccveqcc
提出日時 2019-05-24 22:24:41
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,911 bytes
コンパイル時間 1,190 ms
コンパイル使用メモリ 117,388 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 12:54:18
合計ジャッジ時間 2,393 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/vector:65,
                 from main.cpp:6:
In member function 'std::vector<bool, _Alloc>::reference std::vector<bool, _Alloc>::operator[](size_type) [with _Alloc = std::allocator<bool>]',
    inlined from 'int main()' at main.cpp:44:23:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_bvector.h:1036:23: warning: 'need' may be used uninitialized [-Wmaybe-uninitialized]
 1036 |       { return begin()[__n]; }
      |                ~~~~~~~^
main.cpp: In function 'int main()':
main.cpp:32:9: note: 'need' was declared here
   32 |     int need;
      |         ^~~~

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    string s;
    cin >> s;

    map<int, int> mp;
    for (char c : s) mp[c - '0']++;

    vector<bool> ans(10, false);

    // 2 * 7 のチェック
    int need;
    int count = 0;
    bool flag = true;
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
        if (itr->second == 1) {
            if (count > 0) flag = false;
            need = itr->first;
            count++;
        } else if (itr->second > 2) {
            flag = false;
        }
    }
    if (flag) ans[need] = true;

    // 2 3 3 3 3 のチェック
    for (int i = 1; i < 10; i++) {
        // 挿入する数字がiの時
        if (mp[i] == 4) continue;

        mp[i]++;
        bool possible = false;

        for (int j = 1; j < 10; j++) {
            // 2のペアがjの時
            if (mp[j] < 2) continue;
            mp[j] -= 2;

            map<int, int> mp2;
            for (auto itr = mp.begin(); itr != mp.end(); itr++) mp2[itr->first] = itr->second;

            bool pos = true;
            for (int k = 1; k < 12; k++) {
                if (mp2[k] < 0) pos = false;

                if (mp2[k] >= 3) mp2[k] -= 3;
                if (mp2[k] > 0) {
                    mp2[k + 1] -= mp2[k];
                    mp2[k + 2] -= mp2[k];
                }
            }

            if (pos) possible = true;
            mp[j] += 2;
        }

        if (possible) ans[i] = true;
        mp[i]--;
    }

    for (int i = 1; i < 10; i++) {
        if (ans[i]) {
            cout << i << "\n";
        }
    }

    return 0;
}
0