답안 #771716

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
771716 2023-07-03T08:21:18 Z PAndaS Fountain (eJOI20_fountain) C++14
30 / 100
64 ms 10588 KB
#include<bits/stdc++.h>

using namespace std;

long find_next(vector<long> d, long i){
    long orig = d[i];
    for(int j = i + 1; j < d.size(); j++) if(d[j] > orig) return j;
    return -1;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long n, q;
    cin >> n >> q;
    vector<long> d(n);
    vector<int> c(n);
    for(long i = 0; i < n; i++) cin >> d[i] >> c[i];
    if( n <= 1000 && q <= 2000){
        vector<vector<pair<long, long>>> paths(n, vector<pair<long, long>>());
        long tmp;
        for(long i = 0; i < n; i++){
            tmp = i;
            while(tmp != -1){
                paths[i].push_back(pair<long, long>(c[tmp], tmp));
                tmp = find_next(d, tmp);
            }
            paths[i].push_back(pair<long, long>(LONG_MAX, -1));
        }
        for(long i = 0; i < n; i++){
            for(long j = 1; j < paths[i].size() - 1; j++){
                paths[i][j].first += paths[i][j - 1].first;
            }
        }
        long res, v;
        long l, r, m;
        for(long i = 0; i < q; i++){
            cin >> res >> v;
            res--;
            l = 0;
            r = paths[res].size() - 1;
            while(l < r){
                m = (l + r) / 2;
                if(paths[res][m].first >= v) r = m;
                else l = m + 1;
            }
            cout << paths[res][r].second + 1 << '\n';
        }
    }
    else{
        vector<long long> pr(n + 1, 0);
        for(long i = 1; i <= n; i++) pr[i] = pr[i - 1] + c[i - 1];
        long res, v;
        long l, r, m;
        for(long i = 0; i < q; i++){
            cin >> res >> v;
            l = res;
            r = n;
            while(l < r){
                m = (l + r) / 2;
                if(pr[m] - pr[res - 1] >= v) r = m;
                else l = m + 1;
            }
            cout << (r ^ n ? r + 1 : 0) << '\n';
        }
    }
    return 0;
}

Compilation message

fountain.cpp: In function 'long int find_next(std::vector<long int>, long int)':
fountain.cpp:7:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 |     for(int j = i + 1; j < d.size(); j++) if(d[j] > orig) return j;
      |                        ~~^~~~~~~~~~
fountain.cpp: In function 'int main()':
fountain.cpp:32:31: warning: comparison of integer expressions of different signedness: 'long int' and 'std::vector<std::pair<long int, long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |             for(long j = 1; j < paths[i].size() - 1; j++){
      |                             ~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 3 ms 596 KB Output is correct
5 Correct 64 ms 10588 KB Output is correct
6 Correct 22 ms 4284 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 54 ms 2832 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 3 ms 596 KB Output is correct
5 Correct 64 ms 10588 KB Output is correct
6 Correct 22 ms 4284 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Incorrect 54 ms 2832 KB Output isn't correct
9 Halted 0 ms 0 KB -