답안 #938961

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
938961 2024-03-06T01:46:53 Z riariti 나머지들의 합 (NOI12_modsum) C++17
25 / 25
1 ms 360 KB
#include <bits/stdc++.h>

constexpr int K = 5;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n;
    std::cin >> n;
    std::vector<int> v(n), w(n);
    for (int i = 0; i < 2 * n; i++) {
        auto k = i / 2;
        std::cin >> (i % 2 ? w[k] : v[k]);
    }

    std::array<int, K> cnt{};
    cnt[0] = 1;
    // you can get sum of% 5 = 0 in 1 way when there are no elements
    // since sum of no elements is 0
    for (int i = 0; i < n; i++) {
        std::array<int, 5> cur{};

        for (int j = v[i]; j <= w[i]; j++) {
            for (int k = 0; k < K; k++) {
                cur[(j + k) % K] += cnt[k];
            }
        }

        std::swap(cnt, cur);
    }

    std::int64_t ans = 0;

    for (int i = 0; i < K; i++) {
        std::int64_t v = std::pow(i, 4) + 2 * std::pow(i, 2);

        ans += cnt[i] * (v % K + 1);
    }

    std::cout << ans << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 360 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct