Submission #936075

# Submission time Handle Problem Language Result Execution time Memory
936075 2024-03-01T05:55:14 Z guagua0407 Naan (JOI19_naan) C++17
100 / 100
110 ms 95608 KB
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pll pair<ll,int>

int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};

void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

inline char readchar(){
    const int maxn=1000000;
    static char buf[maxn],*p=buf,*q=buf;
    if(p==q&&(q=(p=buf)+fread(buf,1,maxn,stdin))==buf) return EOF;
    else return *p++;
}
inline int readint(){
    int c=readchar(),x=0,neg=0;
    while((c<'0'||c>'9')&&c!='-'&&c!=EOF) c=readchar();
    if(c=='-') neg=1,c=readchar();
    while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^'0'),c=readchar();
    return neg?-x:x;
}

bool les(pll &a,pll &b){
    return (__int128)a.f*b.s<(__int128)a.s*b.f;
}

signed main() {_
    int n,l;
    n=readint();
    l=readint();
    vector<vector<int>> v0(n,vector<int>(l));
    vector<vector<int>> v(n,vector<int>(l));
    vector<int> sum(n);
    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            v0[i][j]=readint();
            sum[i]+=v0[i][j];
            v[i][j]=v0[i][j]*n;
        }
    }
    vector<vector<pll>> cut(n,vector<pll>(n));
    for(int i=0;i<n;i++){
        int pos=0;
        int rem=v[i][0];
        for(int j=0;j<n-1;j++){
            int now=sum[i];
            while(pos<l and rem<=now){
                now-=rem;
                pos++;
                rem=v[i][pos];
            }
            rem-=now;
            cut[i][j]={1ll*v[i][pos]*(pos+1)-rem,v[i][pos]};
        }
    }
    vector<bool> used(n);
    vector<int> ans;
    for(int i=0;i<n;i++){
        int mn=-1;
        for(int j=0;j<n;j++){
            if(used[j]) continue;
            if(mn==-1) mn=j;
            else if(les(cut[j][i],cut[mn][i])){
                mn=j;
            }
        }
        ans.push_back(mn);
        used[mn]=true;
    }
    for(int i=0;i<n-1;i++){
        cout<<cut[ans[i]][i].f<<' '<<cut[ans[i]][i].s<<'\n';
    }
    for(int i=0;i<n;i++){
        cout<<ans[i]+1<<' ';
    }
    return 0;
}
//maybe its multiset not set
//yeeorz
//laborz

Compilation message

naan.cpp: In function 'void setIO(std::string)':
naan.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
naan.cpp:17:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 600 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 600 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 11 ms 8544 KB Output is correct
44 Correct 53 ms 44116 KB Output is correct
45 Correct 29 ms 19024 KB Output is correct
46 Correct 4 ms 3160 KB Output is correct
47 Correct 36 ms 27712 KB Output is correct
48 Correct 53 ms 63312 KB Output is correct
49 Correct 14 ms 17240 KB Output is correct
50 Correct 76 ms 82260 KB Output is correct
51 Correct 32 ms 31812 KB Output is correct
52 Correct 70 ms 73044 KB Output is correct
53 Correct 56 ms 63828 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 25 ms 33008 KB Output is correct
56 Correct 42 ms 44892 KB Output is correct
57 Correct 35 ms 37540 KB Output is correct
58 Correct 54 ms 62292 KB Output is correct
59 Correct 36 ms 37712 KB Output is correct
60 Correct 110 ms 95504 KB Output is correct
61 Correct 106 ms 95316 KB Output is correct
62 Correct 106 ms 94900 KB Output is correct
63 Correct 102 ms 95568 KB Output is correct
64 Correct 109 ms 95572 KB Output is correct
65 Correct 91 ms 95572 KB Output is correct
66 Correct 97 ms 95564 KB Output is correct
67 Correct 102 ms 95608 KB Output is correct
68 Correct 43 ms 44400 KB Output is correct
69 Correct 45 ms 42332 KB Output is correct
70 Correct 51 ms 54240 KB Output is correct
71 Correct 68 ms 65108 KB Output is correct