QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#461387#3101. Event Hopping 2AmrT0 8ms6312kbC++232.4kb2024-07-02 18:30:002024-07-02 18:30:03

Judging History

你现在查看的是最新测评结果

  • [2024-07-02 18:30:03]
  • 评测
  • 测评结果:0
  • 用时:8ms
  • 内存:6312kb
  • [2024-07-02 18:30:00]
  • 提交

answer

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define lop(i, n) for(ll i = 0; i < (ll)n; i++)
#define in(v) for(auto &i: v) cin >> i;
#define alop(i,v) for(auto &i: v)
#define ll long long
#define ld long double
#define endl '\n'
#define all(v) v.begin(),v.end()
#define mem(dp, x) memset(dp, x, sizeof(dp))
#define sq(x) ((x) * (x))
#define pb push_back
using namespace std;

ll bs(vector<pair<ll, ll>> &arr, ll x){
    ll l = 0, r = arr.size() - 1, mid, ans = 1e18;
    while(l <= r){
        mid = (l + r) / 2;
        if(arr[mid].first <= x) 
            ans = mid, l = mid + 1;
        else 
            r = mid - 1;
    }
    return ans;
}

signed main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    ll n, k; cin >> n >> k;
    vector<pair<ll, ll>> arr(n); //{r, l}
    map<pair<ll, ll>, ll> mp;
    lop(i, n){
        ll a, b; cin >> a >> b;
        arr[i] = {b, a};
        mp[{b, a}] = i;
    }
    sort(all(arr));

    vector<vector<ll>> dp(k + 1, vector<ll>(n, 1e18));
    vector<vector<ll>> par(k + 1, vector<ll>(n, -1));
    lop(i, n){
        dp[1][i] = 0, par[1][i] = i;
    }

    for(int i = 2; i <= k; i++){
        lop(j, n){
            ll res = bs(arr, arr[j].second);
            if(res == 1e18) continue;
            ll g = dp[i - 1][res];

            if(g == 1e18) continue;

            par[i][j] = g;
            dp[i][j] = j;
            if(j)
                dp[i][j] = min(dp[i][j - 1], j);
        }
    }

    vector<vector<ll>> sol;
    lop(i, n){
        ll g = dp[k][i];
        if(g == 1e18) continue;
        vector<ll> temp = {mp[arr[i]]};

        ll j = k, ind = i;
        while(par[j][ind] != ind){
            ind = par[j][ind], j--;
            temp.pb(mp[arr[ind]]);
        }
        sort(all(temp));
        sol.pb(temp);
    }

    if(sol.empty()) cout << -1;
    else{
        set<ll> cmp;
        lop(i, sol.size()) 
            cmp.insert(i);
        lop(j, k){
            ll mn = 1e18;
            alop(i, cmp){
                mn = min(mn, sol[i][j]);
            }
            vector<ll> del;
            alop(i, cmp){
                if(sol[i][j] != mn) del.pb(i);
            }
            alop(i, del)
                cmp.erase(cmp.find(i));
        }

        lop(i, k)
            cout << sol[0][i] + 1 << endl;
    }

    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

score: 7
Accepted
time: 1ms
memory: 3484kb

input:

1 1
1 3

output:

1

result:

ok single line: '1'

Test #2:

score: 7
Accepted
time: 0ms
memory: 3544kb

input:

2 1
2 4
3 7

output:

1

result:

ok single line: '1'

Test #3:

score: 7
Accepted
time: 0ms
memory: 3608kb

input:

3 1
2 5
3 5
4 7

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Time Limit Exceeded

input:

99999 93097
40044 40749
44538 45365
46530 47401
52845 53481
59519 60065
86226 87059
88353 88992
95665 96502
95669 96575
100446 100968
121870 122544
130836 131540
146294 147230
151177 151970
160381 161376
164174 165119
166582 167438
169062 169687
173200 173849
177329 178217
189213 189811
249372 25029...

output:


result:


Subtask #2:

score: 0
Wrong Answer

Test #47:

score: 1
Accepted
time: 1ms
memory: 3732kb

input:

1 1
134842099 137944073

output:

1

result:

ok single line: '1'

Test #48:

score: 1
Accepted
time: 0ms
memory: 3728kb

input:

2 2
4015595 884953730
519508315 726912949

output:

-1

result:

ok single line: '-1'

Test #49:

score: 0
Wrong Answer
time: 1ms
memory: 3496kb

input:

3 2
551691302 800582045
14063803 52897269
153641504 567834643

output:

2
3

result:

wrong answer 1st lines differ - expected: '1', found: '2'

Subtask #3:

score: 0
Wrong Answer

Test #74:

score: 0
Wrong Answer
time: 8ms
memory: 6312kb

input:

3000 57
226083340 261990234
392684356 462929590
468018811 841719892
495096853 606046097
196983814 256423598
331199122 967656486
802593662 931108452
74501453 679054962
294344294 752837262
295708332 547261648
265421699 652708933
272959087 727136240
165667761 846917534
61770748 157663302
608516043 8492...

output:

-1

result:

wrong answer 1st lines differ - expected: '50', found: '-1'

Subtask #4:

score: 0
Time Limit Exceeded

Test #111:

score: 0
Time Limit Exceeded

input:

100000 361
136798318 785362988
255943758 535488232
175203444 266819907
766993466 893575347
67274251 589651108
662289594 883406317
830803801 849703610
729398668 798198453
202605534 677648797
66407931 925909114
174421361 601553812
522629146 701284080
136544340 295925673
299796891 499869765
736583725 8...

output:


result: