結果

問題 No.1919 Many Monster Battles
ユーザー SSRSSSRS
提出日時 2022-04-29 22:54:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,685 bytes
コンパイル時間 1,808 ms
コンパイル使用メモリ 178,928 KB
実行使用メモリ 13,304 KB
最終ジャッジ日時 2023-09-11 14:19:37
合計ジャッジ時間 6,451 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++){
    cin >> a[i];
  }
  vector<int> b(N);
  for (int i = 0; i < N; i++){
    cin >> b[i];
  }
  vector<long long> ans(2, 0);
  for (int i = 0; i < 2; i++){
    vector<pair<int, int>> P(N);
    for (int j = 0; j < N; j++){
      P[j] = make_pair(a[j], b[j]);
    }
    sort(P.begin(), P.end());
    for (int j = 0; j < N; j++){
      a[j] = P[j].first;
      b[j] = P[j].second;
    }
    vector<pair<int, int>> P2(N);
    for (int j = 0; j < N; j++){
      P2[j] = make_pair(b[j], j);
    }
    sort(P2.begin(), P2.end());
    vector<int> id(N);
    for (int j = 0; j < N; j++){
      id[j] = P2[j].second;
    }
    vector<bool> used1(N, false);
    for (int j = 0; j < N; j++){
      int p = id[j];
      for (int k = 0; k < p; k++){
        if (used1[k] && a[p] - b[p] > a[k] - b[k]){
          ans[i] += a[p];
        }
      }
      for (int k = p + 1; k < N; k++){
        if (used1[k] && a[p] + b[p] < a[k] + b[k]){
          ans[i] -= a[p];
        }
      }
      used1[p] = true;
    }
    vector<bool> used2(N, false);
    for (int j = N - 1; j >= 0; j--){
      int p = id[j];
      for (int k = 0; k < p; k++){
        if (used2[k] && a[p] + b[p] > a[k] + b[k]){
          ans[i] += a[p];
        }
      }
      for (int k = p + 1; k < N; k++){
        if (used2[k] && a[p] - b[p] < a[k] - b[k]){
          ans[i] -= a[p];
        }
      }
      used2[p] = true;
    }
    ans[i] %= MOD;
    ans[i] += MOD;
    ans[i] *= 2;
    ans[i] %= MOD;
    swap(a, b);
  }
  cout << ans[0] << ' ' << ans[1] << endl;
}
0