답안 #89225

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
89225 2018-12-11T04:24:12 Z win11905 나머지들의 합 (NOI12_modsum) C++11
25 / 25
3 ms 1376 KB
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author win11905
 */

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define long long long
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
const long MOD = 1e9+7, LINF = 1e18 + 1e16;
const int INF = 1e9+1;
const double EPS = 1e-10;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};

const int N = 1<<10;
int n;

class modsum {
private:
    int v[N], w[N];
    int mnk[N << 1];
    vector<long> vec[N << 1];
    long ans;
    void rec(int p = 1, int l = 1, int r = n) {
        if(l == r) {
            mnk[p] = v[l];
            vec[p] = vector<long>(w[r] - v[l] + 1, 1);
            return;
        }
        int m = l + r >> 1;
        rec(p<<1, l, m), rec(p<<1|1, m+1, r);
        mnk[p] = mnk[p<<1] + mnk[p<<1|1];
        vec[p] = vector<long>(vec[p<<1].size() + vec[p<<1|1].size() - 1, 0);
        for(int i = 0; i < vec[p<<1].size(); ++i) for(int j = 0; j < vec[p<<1|1].size(); ++j)
            vec[p][i+j] += vec[p<<1][i] * vec[p<<1|1][j];
    }

public:
    void solve(istream& cin, ostream& cout) {
        cin >> n;
        for(int i = 1; i <= n; ++i) cin >> v[i] >> w[i];
        rec();
        for(int i = 0; i < vec[1].size(); ++i) {
            long now = i + mnk[1];
            now = now * now % 5;
            now = now * (now + 2) % 5;
            ans += vec[1][i] * (now + 1);
        }
        cout << ans << endl;
    }
};

class Solver {
public:
    void solve(std::istream& in, std::ostream& out) {
        modsum *obj = new modsum();
        obj->solve(in, out);
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    Solver solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}

Compilation message

modsum.cpp: In member function 'void modsum::rec(int, int, int)':
modsum.cpp:34:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int m = l + r >> 1;
                 ~~^~~
modsum.cpp:38:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i < vec[p<<1].size(); ++i) for(int j = 0; j < vec[p<<1|1].size(); ++j)
                        ~~^~~~~~~~~~~~~~~~~~
modsum.cpp:38:68: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i < vec[p<<1].size(); ++i) for(int j = 0; j < vec[p<<1|1].size(); ++j)
                                                                  ~~^~~~~~~~~~~~~~~~~~~~
modsum.cpp: In member function 'void modsum::solve(std::istream&, std::ostream&)':
modsum.cpp:47:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i < vec[1].size(); ++i) {
                        ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 552 KB Output is correct
2 Correct 2 ms 712 KB Output is correct
3 Correct 2 ms 824 KB Output is correct
4 Correct 2 ms 824 KB Output is correct
5 Correct 2 ms 824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 896 KB Output is correct
2 Correct 2 ms 896 KB Output is correct
3 Correct 1 ms 984 KB Output is correct
4 Correct 2 ms 1036 KB Output is correct
5 Correct 2 ms 1036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1036 KB Output is correct
2 Correct 2 ms 1036 KB Output is correct
3 Correct 2 ms 1036 KB Output is correct
4 Correct 2 ms 1036 KB Output is correct
5 Correct 2 ms 1076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1376 KB Output is correct
2 Correct 3 ms 1376 KB Output is correct
3 Correct 2 ms 1376 KB Output is correct
4 Correct 2 ms 1376 KB Output is correct
5 Correct 2 ms 1376 KB Output is correct