Submission #685739

# Submission time Handle Problem Language Result Execution time Memory
685739 2023-01-24T23:29:55 Z divad Trampoline (info1cup20_trampoline) C++14
73 / 100
2000 ms 13548 KB
/// solutia optima (care ia 100p) se face cu binary shifting, dar mi-e lene sa implementez
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <map>
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()
using namespace std;
int r,c,n,T,x1,x2,y1,y2;
vector<pii> secv;
map<int, vector<int>> mp;

bool trecut(pii s, int x){
    return (s.first >= x || x <= s.second);
}

bool inclus(pii s, int x){
    return (s.first <= x && x <= s.second);
}

int next_pos(int row, int col){
    int st = 0, dr = mp[row].size()-1;
    int ans = -1;
    while(st <= dr){
        int mid = ((st+dr)>>1);
        if(mp[row][mid] >= col){
            ans = mid;
            dr = mid-1;
        }else{
            st = mid+1;
        }
    }
    if(ans != -1){
        return mp[row][ans];
    }
    return ans;
}

void solve(){
    cin >> x1 >> y1 >> x2 >> y2;
    if(x1 > x2 || y1 > y2){
        cout << "No\n"; return ;
    }
    if(x1 == x2){
        cout << "Yes\n"; return ;
    }
    int st = 0, dr = secv.size()-1;
    int ans = -1;
    while(st <= dr){
        int mid = ((st+dr)>>1);
        if(trecut(secv[mid], x1)){
            ans = mid;
            dr = mid-1;
        }else{
            st = mid+1;
        }
    }
    if(ans == -1){
        cout << "No\n";
        return ;
    }
    if(!inclus(secv[ans], x2)){
        cout << "No\n"; return ;
    }
    bool ok = true;
    while(x1 < x2){
        y1 = next_pos(x1, y1);
        if(y1 == -1){
            ok = false;
            break;
        }
        x1++;
    }
    if(ok){
        ok = (y1 <= y2);
    }
    cout << (ok ? "Yes" : "No") << "\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> r >> c >> n;
    for(int i = 1; i <= n; i++){
        cin >> x1 >> y1;
        mp[x1].push_back(y1);
    }
    int ind = -1;
    for(auto [row, v]: mp){
        sort(all(mp[row]));
        if(secv.size() == 0){
            secv.push_back({row, row+1});
            ind++;
        }else{
            if(row == secv[ind].second){
                secv[ind].second = row+1;
            }else{
                secv.push_back({row, row+1});
                ind++;
            }
        }
    }
    cin >> T;
    while(T--){
        solve();
    }
    return 0;
}

Compilation message

trampoline.cpp: In function 'int main()':
trampoline.cpp:91:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   91 |     for(auto [row, v]: mp){
      |              ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 468 KB 200 token(s): yes count is 21, no count is 179
2 Correct 5 ms 468 KB 200 token(s): yes count is 70, no count is 130
3 Correct 4 ms 400 KB 197 token(s): yes count is 25, no count is 172
# Verdict Execution time Memory Grader output
1 Correct 134 ms 2792 KB 4000 token(s): yes count is 99, no count is 3901
2 Correct 127 ms 2508 KB 4000 token(s): yes count is 91, no count is 3909
3 Correct 424 ms 1976 KB 4000 token(s): yes count is 4000, no count is 0
4 Correct 827 ms 2472 KB 4000 token(s): yes count is 1991, no count is 2009
# Verdict Execution time Memory Grader output
1 Correct 177 ms 3000 KB 200000 token(s): yes count is 110486, no count is 89514
2 Correct 168 ms 2644 KB 200000 token(s): yes count is 114664, no count is 85336
3 Correct 183 ms 2512 KB 200000 token(s): yes count is 86232, no count is 113768
4 Correct 248 ms 7564 KB 200000 token(s): yes count is 94603, no count is 105397
5 Correct 266 ms 7516 KB 200000 token(s): yes count is 94148, no count is 105852
6 Correct 331 ms 13548 KB 200000 token(s): yes count is 97163, no count is 102837
# Verdict Execution time Memory Grader output
1 Correct 6 ms 596 KB 5000 token(s): yes count is 3238, no count is 1762
2 Correct 14 ms 632 KB 5000 token(s): yes count is 3837, no count is 1163
3 Correct 8 ms 1252 KB 5000 token(s): yes count is 4104, no count is 896
4 Correct 6 ms 596 KB 5000 token(s): yes count is 3934, no count is 1066
5 Correct 422 ms 716 KB 5000 token(s): yes count is 3384, no count is 1616
6 Correct 5 ms 596 KB 5000 token(s): yes count is 3390, no count is 1610
# Verdict Execution time Memory Grader output
1 Execution timed out 2036 ms 9448 KB Time limit exceeded
2 Halted 0 ms 0 KB -