結果
| 問題 | 
                            No.200 カードファイト!
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2017-05-11 17:33:46 | 
| 言語 | D  (dmd 2.109.1)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 1 ms / 2,000 ms | 
| コード長 | 1,301 bytes | 
| コンパイル時間 | 864 ms | 
| コンパイル使用メモリ | 123,888 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-12 19:11:43 | 
| 合計ジャッジ時間 | 1,614 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 26 | 
ソースコード
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;
void main() {
    auto N = readln.chomp.to!int;
    auto aa = readln.chomp.to!int;
    auto AO = readln.split.map!(to!int).array;
    AO.sort();
    auto A = AO.dup;
    auto bb = readln.chomp.to!int;
    auto BO = readln.split.map!(to!int).array;
    BO.sort();
    auto B = BO.dup;
    
    int ans = 0;
    
    foreach (k; 0..N) {
        bool played = false;
        int pi, pj;
        foreach (i; 0..A.length.to!int) {
            foreach (j; iota(B.length.to!int-1, -1, -1)) {
                if (A[i] > B[j]) {
                    pi = i;
                    pj = j;
                    played = true;
                    break;
                }
            }
            if (played) break;
        }
        if (played) {
            A = A[0..pi] ~ A[pi+1..$];
            B = B[0..pj] ~ B[pj+1..$];
            ans += 1;
            if (A.length == 0) A = AO.dup;
            if (B.length == 0) B = BO.dup;
        }
        else {
            A = A[1..$];
            B = B[0..$-1];
            if (A.length == 0) A = AO.dup;
            if (B.length == 0) B = BO.dup;
        }
    }
    ans.writeln;
}