結果

問題 No.200 カードファイト!
ユーザー mayoko_mayoko_
提出日時 2015-07-29 07:51:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,037 bytes
コンパイル時間 724 ms
コンパイル使用メモリ 80,244 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-05 11:56:09
合計ジャッジ時間 1,953 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
#include<complex>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const int MAXN = 55;
int B[MAXN], D[MAXN];
int A, C, N;

bool done[2][MAXN];
int cnta = 0, cntc = 0;

int ok(int a) {
    for (int j = C-1; j >= 0; j--) {
        if (done[1][j]) continue;
        if (D[j] < B[a]) return j;
    }
    return -1;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    cin >> A;
    for (int i = 0; i < A; i++) cin >> B[i];
    cin >> C;
    for (int i = 0; i < C; i++) cin >> D[i];
    sort(B, B+A);
    sort(D, D+C);
    int ans = 0;
    for (int t = 0; t < N; t++) {
        if (cnta >= A) {
            cnta = 0;
            memset(done[0], false, sizeof(done[0]));
        }
        if (cntc >= C) {
            cntc = 0;
            memset(done[1], false, sizeof(done[1]));
        }
        int a = -1, c = -1;
        for (int i = A-1; i >= 0; i--) {
            if (done[0][i]) continue;
            int tmp = ok(i);
            if (tmp == -1) break;
            a = i;
            c = tmp;
        }
        if (a != -1) {
            ans++;
            done[0][a] = true;
            done[1][c] = true;
        } else {
            for (int i = 0; i < A; i++) if (!done[0][i]) {
                a = i;
                break;
            }
            for (int i = C-1; i >= 0; i--) if (!done[1][i]) {
                c = i;
                break;
            }
            done[0][a] = true;
            done[1][c] = true;
        }
        cnta++;
        cntc++;
    }
    cout << ans << endl;
    return 0;
}
0