Submission #703807

# Submission time Handle Problem Language Result Execution time Memory
703807 2023-02-28T12:23:29 Z Darren0724 Naan (JOI19_naan) C++17
100 / 100
374 ms 125956 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
const int INF=1e18;
bool operator<(pair<int,int> a,pair<int,int> b){
    return (__int128)a.first*b.second<(__int128)a.second*b.first;
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,m;cin>>n>>m;
    vector<int> a(n);
    vector<vector<int>> v(n,vector<int>(m)),pre(n,vector<int>(m));
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>v[i][j];
            v[i][j]*=n;
            a[i]+=v[i][j];
        }
        a[i]/=n;
    }
    for(int i=0;i<n;i++){
        pre[i][0]=v[i][0];
        for(int j=1;j<m;j++){
            pre[i][j]=pre[i][j-1]+v[i][j];
        }
    }
    vector<bool> vis(n);
    vector<vector<pair<int,int>>> rec(n,vector<pair<int,int>>(n));
    for(int i=0;i<n;i++){
        int need=0;
        int ptr=0;
        for(int j=0;j<n-1;j++){
            need+=a[i];
            while(ptr<m&&pre[i][ptr]<need){
                ptr++;
            }
            int p=(ptr>0?pre[i][ptr-1]:0);
            rec[i][j]={need-p+ptr*v[i][ptr],v[i][ptr]};
        }
    }
    vector<int> ans(n);
    for(int i=0;i<n-1;i++){
        int idx=-1;
        for(int j=0;j<n;j++){
            if(vis[j]){
                continue;
            }
            if(idx==-1){
                idx=j;
            }
            else if(rec[j][i]<rec[idx][i]){
                idx=j;
            }
        }
        ans[i]=idx+1;
        vis[idx]=1;
        cout<<rec[idx][i].first<<' '<<rec[idx][i].second<<endl;
    }
    for(int i=0;i<n;i++){
        if(vis[i]==0){
            ans[n-1]=i+1;
        }
    }
    for(int j=0;j<n;j++){
        cout<<ans[j]<<' ';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 404 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 404 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 2 ms 468 KB Output is correct
43 Correct 30 ms 9428 KB Output is correct
44 Correct 165 ms 56572 KB Output is correct
45 Correct 126 ms 28020 KB Output is correct
46 Correct 16 ms 3548 KB Output is correct
47 Correct 124 ms 37540 KB Output is correct
48 Correct 100 ms 68928 KB Output is correct
49 Correct 45 ms 20044 KB Output is correct
50 Correct 201 ms 101340 KB Output is correct
51 Correct 142 ms 44376 KB Output is correct
52 Correct 228 ms 97452 KB Output is correct
53 Correct 166 ms 80468 KB Output is correct
54 Correct 1 ms 468 KB Output is correct
55 Correct 49 ms 33740 KB Output is correct
56 Correct 154 ms 60856 KB Output is correct
57 Correct 117 ms 49556 KB Output is correct
58 Correct 185 ms 76652 KB Output is correct
59 Correct 131 ms 53220 KB Output is correct
60 Correct 374 ms 125572 KB Output is correct
61 Correct 368 ms 125688 KB Output is correct
62 Correct 370 ms 124940 KB Output is correct
63 Correct 370 ms 125800 KB Output is correct
64 Correct 373 ms 125828 KB Output is correct
65 Correct 292 ms 125744 KB Output is correct
66 Correct 300 ms 125956 KB Output is correct
67 Correct 292 ms 125832 KB Output is correct
68 Correct 131 ms 56116 KB Output is correct
69 Correct 163 ms 58248 KB Output is correct
70 Correct 151 ms 67228 KB Output is correct
71 Correct 258 ms 88032 KB Output is correct