結果

問題 No.1279 Array Battle
ユーザー kpinkcatkpinkcat
提出日時 2023-08-31 16:28:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 1,525 bytes
コンパイル時間 1,482 ms
コンパイル使用メモリ 108,392 KB
実行使用メモリ 5,224 KB
最終ジャッジ日時 2023-08-31 16:29:02
合計ジャッジ時間 2,920 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 5 ms
4,376 KB
testcase_14 AC 3 ms
4,384 KB
testcase_15 AC 16 ms
5,164 KB
testcase_16 AC 18 ms
5,076 KB
testcase_17 AC 26 ms
5,144 KB
testcase_18 AC 33 ms
5,224 KB
testcase_19 AC 25 ms
5,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<map>
#include<vector>
#include <algorithm>
#include<math.h>
#include <iomanip>
#include<set>
#include <numeric>
#include<string>
using namespace std;

int main()
{
    int n, cnt = 0;
    cin >> n;
    vector<int> a(n), b(n), r(n), sum1;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    //next_permutation は配列に同じ値があった場合、重複を自動で省き、数に数えない。
    //そのため、重複分も検討したいときにはダミー配列を使用する。
    //ここでは、ダミー配列 r に index と同じ値を格納し、確実に順列を生成させる。
    //値の比較は a と b の配列で行うが、a の値は a[r[i]] と置くことで、
    //重複部分も比較させている。
    for (int i = 0; i < n; i++) r[i] = i;
    //ダミー配列 r は昇順になっているので、ソートする必要はない。
    do {
        int tsum = 0;
        for (int i = 0; i < n; i ++){
            //もし、a が昇順ソート済みであれば a[i]としても問題ない。
            if (a[r[i]] > b[i]) tsum += (a[r[i]] - b[i]);
        }
        sum1.push_back(tsum);
        //next_permutation の引数は a ではなく、r となっている点に注意。
    }while (next_permutation(r.begin(), r.end()));
    sort(sum1.begin(), sum1.end(), greater());
    for (int i = 0; i < sum1.size(); i++){
        if (sum1[i] == sum1[0]) cnt++;
    }
    cout << cnt << endl;
}   
0