QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#461363#3101. Event Hopping 2AmrT0 13ms7640kbC++232.7kb2024-07-02 18:20:382024-07-02 18:20:38

Judging History

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

  • [2024-07-02 18:20:38]
  • 评测
  • 测评结果:0
  • 用时:13ms
  • 内存:7640kb
  • [2024-07-02 18:20:38]
  • 提交

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;

struct node{
    ll mn = 1e18, ind = 1e18;
    friend node operator+(node a, node b){
        if(a.mn <= b.mn) 
            return a;
        else 
            return b;
    }
};

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<node>> dp(k + 1, vector<node>(n));
    vector<vector<ll>> par(k + 1, vector<ll>(n, -1));
    lop(i, n){
        dp[1][i] = (node){arr[i].second, i}, par[1][i] = i;
        if(i) 
            dp[1][i] = dp[1][i - 1] + dp[1][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].ind;

            if(g == 1e18) continue;

            par[i][j] = g;
            dp[i][j] = (node){arr[j].second, j};
            if(j)
                dp[i][j] = dp[i][j - 1] + dp[i][j];
        }
    }

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

        ll j = k, ind = i;
        while(par[j][ind] != ind){
            ind = par[j][ind], j--;

            temp.pb({arr[ind].second, mp[arr[ind]]});
        }
        reverse(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].first);
            }
            vector<ll> del;
            alop(i, cmp){
                if(sol[i][j].first != mn) del.pb(i);
            }
            alop(i, del)
                cmp.erase(cmp.find(i));
        }

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

    
    return 0;
}

詳細信息

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

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

input:

1 1
1 3

output:

1

result:

ok single line: '1'

Test #2:

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

input:

2 1
2 4
3 7

output:

1

result:

ok single line: '1'

Test #3:

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

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: 3684kb

input:

1 1
134842099 137944073

output:

1

result:

ok single line: '1'

Test #48:

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

input:

2 2
4015595 884953730
519508315 726912949

output:

-1

result:

ok single line: '-1'

Test #49:

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

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: 13ms
memory: 7640kb

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: