답안 #771732

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

using namespace std;

ifstream fin("test.txt");

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;
    fin >> n >> q;
    vector<long> d(n);
    vector<int> c(n);
    for(long i = 0; i < n; i++) fin >> 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++){
            fin >> 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 : 0) << '\n';
        }
    }
    return 0;
}

Compilation message

fountain.cpp: In function 'long int find_next(std::vector<long int>, long int)':
fountain.cpp:9:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |     for(int j = i + 1; j < d.size(); j++) if(d[j] > orig) return j;
      |                        ~~^~~~~~~~~~
fountain.cpp: In function 'int main()':
fountain.cpp:34: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]
   34 |             for(long j = 1; j < paths[i].size() - 1; j++){
      |                             ~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 416 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 416 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -