답안 #675156

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
675156 2022-12-27T02:16:11 Z vjudge1 Trampoline (info1cup20_trampoline) C++17
100 / 100
415 ms 26188 KB
#include <bits/stdc++.h>
using namespace std;
int r, c;
const int LG = 20;
vector<pair<int, int>> a;
vector<vector<int>> jmps;
void build_jumps(){
    jmps.assign(a.size(), vector<int> (20));
    for (int i=a.size()-1; i>=0; i--){
        vector<pair<int, int>>::iterator it =
            lower_bound(a.begin(), a.end(), make_pair(a[i].first+1, a[i].second));
        if (it == a.end() || it->first != a[i].first + 1) it = a.end();
        int ptr = it - a.begin();
        jmps[i][0] = ptr;
        for (int p=1; p<LG; p++){
            int dn = jmps[i][p-1];
            if (dn == a.size()) jmps[i][p] = a.size();
            else jmps[i][p] = jmps[dn][p-1];
        }
    }
}
int jump(int ptr, int step){
    if (ptr == a.size()) return a.size();
    if (step > 1000000) return a.size();
    if (step == 0) return ptr;
    int lg2 = 31 - __builtin_clz(step);
    return jump(jmps[ptr][lg2], step - (1<<lg2));
}
bool solve(int xf, int yf, int xt, int yt){
    if (yt < yf || xt < xf)
        return false;
    if (xf == xt)
        return true;
    vector<pair<int, int>>::iterator it =
        lower_bound(a.begin(), a.end(), make_pair(xf, yf));
    if (it == a.end() || it->first != xf)
        return false;
    int ptrstart = it - a.begin();
    int dest = jump(ptrstart, xt - xf - 1);
    if (dest == a.size() || a[dest].second > yt) return false;
    return true;
}
signed main(){
    cin.tie(0)->sync_with_stdio(0);
    cin >> r >> c;
    int n; cin >> n;
    a.resize(n);
    for (int i=0; i<n; i++)
        cin >> a[i].first >> a[i].second;
    sort(a.begin(), a.end());
    build_jumps();
    int t; cin >> t;
    while (t--){
        int xf, yf, xt, yt; cin >> xf >> yf >> xt >> yt;
        if (solve(xf, yf, xt, yt))
            cout << "Yes\n";
        else
            cout << "No\n";
    }
}

Compilation message

trampoline.cpp: In function 'void build_jumps()':
trampoline.cpp:17:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |             if (dn == a.size()) jmps[i][p] = a.size();
      |                 ~~~^~~~~~~~~~~
trampoline.cpp: In function 'int jump(int, int)':
trampoline.cpp:23:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     if (ptr == a.size()) return a.size();
      |         ~~~~^~~~~~~~~~~
trampoline.cpp: In function 'bool solve(int, int, int, int)':
trampoline.cpp:40:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     if (dest == a.size() || a[dest].second > yt) return false;
      |         ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1364 KB 200 token(s): yes count is 21, no count is 179
2 Correct 4 ms 1492 KB 200 token(s): yes count is 70, no count is 130
3 Correct 3 ms 1164 KB 197 token(s): yes count is 25, no count is 172
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 25428 KB 4000 token(s): yes count is 99, no count is 3901
2 Correct 95 ms 25392 KB 4000 token(s): yes count is 91, no count is 3909
3 Correct 89 ms 25364 KB 4000 token(s): yes count is 4000, no count is 0
4 Correct 84 ms 25316 KB 4000 token(s): yes count is 1991, no count is 2009
# 결과 실행 시간 메모리 Grader output
1 Correct 174 ms 26064 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 197 ms 26088 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 210 ms 25980 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 228 ms 25940 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 295 ms 26012 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 228 ms 26008 KB 200000 token(s): yes count is 97163, no count is 102837
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 852 KB 5000 token(s): yes count is 3238, no count is 1762
2 Correct 5 ms 852 KB 5000 token(s): yes count is 3837, no count is 1163
3 Correct 5 ms 852 KB 5000 token(s): yes count is 4104, no count is 896
4 Correct 5 ms 852 KB 5000 token(s): yes count is 3934, no count is 1066
5 Correct 5 ms 852 KB 5000 token(s): yes count is 3384, no count is 1616
6 Correct 4 ms 852 KB 5000 token(s): yes count is 3390, no count is 1610
# 결과 실행 시간 메모리 Grader output
1 Correct 382 ms 26044 KB 200000 token(s): yes count is 171404, no count is 28596
2 Correct 313 ms 26088 KB 200000 token(s): yes count is 161254, no count is 38746
3 Correct 220 ms 26088 KB 200000 token(s): yes count is 117455, no count is 82545
4 Correct 415 ms 26088 KB 200000 token(s): yes count is 182118, no count is 17882
5 Correct 245 ms 26100 KB 200000 token(s): yes count is 167565, no count is 32435
6 Correct 268 ms 26028 KB 200000 token(s): yes count is 156797, no count is 43203
7 Correct 222 ms 26028 KB 200000 token(s): yes count is 156797, no count is 43203
8 Correct 247 ms 26188 KB 200000 token(s): yes count is 122100, no count is 77900
9 Correct 395 ms 25988 KB 200000 token(s): yes count is 139670, no count is 60330
10 Correct 358 ms 26152 KB 200000 token(s): yes count is 165806, no count is 34194
11 Correct 381 ms 26188 KB 200000 token(s): yes count is 175646, no count is 24354
12 Correct 215 ms 26068 KB 200000 token(s): yes count is 134695, no count is 65305
13 Correct 204 ms 26024 KB 200000 token(s): yes count is 126733, no count is 73267
14 Correct 277 ms 26048 KB 200000 token(s): yes count is 155290, no count is 44710
15 Correct 201 ms 26076 KB 200000 token(s): yes count is 129674, no count is 70326