Submission #590282

# Submission time Handle Problem Language Result Execution time Memory
590282 2022-07-05T18:06:18 Z perchuts Naan (JOI19_naan) C++17
100 / 100
445 ms 116332 KB
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define endl '\n'
#define pb push_back
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define f first
#define s second
#define int ll

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ii = pair<int,int>;
using iii = tuple<int,int,int>;

const int inf = 2e9+1;
const int mod = 1e9+7;
const int maxn = 2001;

template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; }
template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; }

ll v[maxn][maxn], sum[maxn];
pair<ll,ll> d[maxn][maxn];
int p[maxn], pode[maxn];

bool menor(pair<ll,ll>a,pair<ll,ll>b){
    if(a.f/a.s!=b.f/b.s)return a.f/a.s>b.f/b.s;
    return (a.f%a.s)*b.s > a.s*(b.f%b.s);
}

int32_t main(){_
    ll n,l;cin>>n>>l;

    for(int i=1;i<=n;++i)for(int j=1;j<=l;++j)cin>>v[i][j], sum[i] += v[i][j];    

    for(int i=1;i<=n;++i){
        ll atual = 1, act = 0;
        d[i][0] = {0,1};
        for(int j=1;j<n;++j){
            while(n*(act+v[i][atual])<=j*sum[i])act += v[i][atual++];
            ll numerador = (sum[i]*j - act*n);
            ll denominador = n*v[i][atual];
            numerador += denominador*(atual-1);
            d[i][j] = {numerador,denominador};
        }
    }   
    
    for(int i=1;i<=n;++i)pode[i] = 1;

    for(int i=1;i<n;++i){
        pair<ll,ll>best = {-1,-1};
        int idx = -1;
        for(int j=1;j<=n;++j){
            if(pode[j]&&(best.f==-1||menor(best,d[j][i])))best = d[j][i], idx = j;
        }
        assert(idx!=-1);
        p[i] = idx, pode[idx] = 0;
    }

    for(int i=1;i<=n;++i)if(pode[i])p[n] = i;

    for(int i=1;i<n;++i)cout<<d[p[i]][i].f<<" "<<d[p[i]][i].s<<endl;
    
    for(int i=1;i<=n;++i)cout<<p[i]<<" \n"[i==n];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 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 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 340 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 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 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 2 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 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 468 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 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 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 0 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 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 340 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 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 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 2 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 27 ms 11908 KB Output is correct
44 Correct 165 ms 53860 KB Output is correct
45 Correct 101 ms 28768 KB Output is correct
46 Correct 19 ms 3988 KB Output is correct
47 Correct 132 ms 42444 KB Output is correct
48 Correct 92 ms 75128 KB Output is correct
49 Correct 52 ms 24020 KB Output is correct
50 Correct 178 ms 95460 KB Output is correct
51 Correct 100 ms 41476 KB Output is correct
52 Correct 203 ms 86908 KB Output is correct
53 Correct 151 ms 80888 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 41 ms 44024 KB Output is correct
56 Correct 125 ms 56252 KB Output is correct
57 Correct 103 ms 49368 KB Output is correct
58 Correct 151 ms 78620 KB Output is correct
59 Correct 115 ms 45968 KB Output is correct
60 Correct 357 ms 116216 KB Output is correct
61 Correct 369 ms 116172 KB Output is correct
62 Correct 433 ms 116060 KB Output is correct
63 Correct 445 ms 116332 KB Output is correct
64 Correct 391 ms 116196 KB Output is correct
65 Correct 258 ms 102968 KB Output is correct
66 Correct 297 ms 102984 KB Output is correct
67 Correct 278 ms 102968 KB Output is correct
68 Correct 131 ms 60124 KB Output is correct
69 Correct 162 ms 56492 KB Output is correct
70 Correct 143 ms 72128 KB Output is correct
71 Correct 217 ms 82148 KB Output is correct