結果

問題 No.1307 Rotate and Accumulate
ユーザー りあんりあん
提出日時 2020-12-04 01:17:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,163 bytes
コンパイル時間 3,058 ms
コンパイル使用メモリ 216,708 KB
実行使用メモリ 9,108 KB
最終ジャッジ日時 2023-10-12 12:21:43
合計ジャッジ時間 24,097 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 RE -
testcase_08 AC 3,132 ms
4,352 KB
testcase_09 AC 4,011 ms
4,352 KB
testcase_10 AC 2,095 ms
4,352 KB
testcase_11 AC 1,829 ms
4,348 KB
testcase_12 AC 2,254 ms
4,356 KB
testcase_13 AC 45 ms
4,356 KB
testcase_14 RE -
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
const long long LM = 1LL << 60;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }
    vector<int> cnt(n);
    for (int i = 0; i < q; ++i) {
        int x;
        cin >> x;
        ++cnt[x];
    }
    vector<int> c(n + 1);
    for (int i = 0; i <= n; ++i) {
        ++c[cnt[i]];
    }
    int freq = -1, ma = 0;
    for (int i = 0; i <= n; ++i) {
        if (ma < c[i]) {
            ma = c[i];
            freq = i;
        }
    }
    vector<int> b(n);
    for (int i = 0; i < n; ++i) {
        b[i] = freq * sum;
        cnt[i] -= freq;
    }
    for (int i = 0; i < n; ++i) {
        if (cnt[i] == 0) continue;
        for (int j = 0; j < n; ++j) {
            b[j] += cnt[i] * a[i + j < n ? i + j : i + j - n];
        }
    }
    for (int i = 0; i < n; ++i) {
        cout << b[i] << (i < n - 1 ? ' ' : '\n');
    }
    return 0;
}
0