답안 #590267

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
590267 2022-07-05T17:34:03 Z perchuts Naan (JOI19_naan) C++17
29 / 100
156 ms 53964 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

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){
    return a.f*b.s > a.s*b.f;
}

int 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;        
        ll act = 0;
        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 = {2e9,1};
        int idx = -1;
        for(int j=1;j<=n;++j){
            if(pode[j]&&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];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 340 KB Output is correct
2 Correct 8 ms 424 KB Output is correct
3 Correct 11 ms 340 KB Output is correct
4 Correct 7 ms 432 KB Output is correct
5 Correct 7 ms 368 KB Output is correct
6 Correct 9 ms 340 KB Output is correct
7 Correct 8 ms 340 KB Output is correct
8 Correct 7 ms 340 KB Output is correct
9 Correct 6 ms 340 KB Output is correct
10 Correct 6 ms 340 KB Output is correct
11 Correct 7 ms 340 KB Output is correct
12 Correct 7 ms 408 KB Output is correct
13 Correct 7 ms 340 KB Output is correct
14 Correct 7 ms 340 KB Output is correct
15 Correct 7 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 404 KB Output is correct
2 Correct 7 ms 464 KB Output is correct
3 Correct 6 ms 468 KB Output is correct
4 Correct 7 ms 468 KB Output is correct
5 Correct 7 ms 468 KB Output is correct
6 Correct 8 ms 448 KB Output is correct
7 Correct 8 ms 424 KB Output is correct
8 Correct 9 ms 468 KB Output is correct
9 Correct 7 ms 468 KB Output is correct
10 Correct 8 ms 468 KB Output is correct
11 Correct 7 ms 468 KB Output is correct
12 Correct 8 ms 340 KB Output is correct
13 Correct 7 ms 416 KB Output is correct
14 Correct 7 ms 468 KB Output is correct
15 Correct 8 ms 468 KB Output is correct
16 Correct 7 ms 468 KB Output is correct
17 Correct 7 ms 500 KB Output is correct
18 Correct 9 ms 468 KB Output is correct
19 Correct 7 ms 468 KB Output is correct
20 Correct 7 ms 468 KB Output is correct
21 Correct 7 ms 468 KB Output is correct
22 Correct 7 ms 468 KB Output is correct
23 Correct 8 ms 340 KB Output is correct
24 Correct 7 ms 468 KB Output is correct
25 Correct 9 ms 468 KB Output is correct
26 Correct 9 ms 340 KB Output is correct
27 Correct 7 ms 456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 340 KB Output is correct
2 Correct 8 ms 424 KB Output is correct
3 Correct 11 ms 340 KB Output is correct
4 Correct 7 ms 432 KB Output is correct
5 Correct 7 ms 368 KB Output is correct
6 Correct 9 ms 340 KB Output is correct
7 Correct 8 ms 340 KB Output is correct
8 Correct 7 ms 340 KB Output is correct
9 Correct 6 ms 340 KB Output is correct
10 Correct 6 ms 340 KB Output is correct
11 Correct 7 ms 340 KB Output is correct
12 Correct 7 ms 408 KB Output is correct
13 Correct 7 ms 340 KB Output is correct
14 Correct 7 ms 340 KB Output is correct
15 Correct 7 ms 340 KB Output is correct
16 Correct 7 ms 404 KB Output is correct
17 Correct 7 ms 464 KB Output is correct
18 Correct 6 ms 468 KB Output is correct
19 Correct 7 ms 468 KB Output is correct
20 Correct 7 ms 468 KB Output is correct
21 Correct 8 ms 448 KB Output is correct
22 Correct 8 ms 424 KB Output is correct
23 Correct 9 ms 468 KB Output is correct
24 Correct 7 ms 468 KB Output is correct
25 Correct 8 ms 468 KB Output is correct
26 Correct 7 ms 468 KB Output is correct
27 Correct 8 ms 340 KB Output is correct
28 Correct 7 ms 416 KB Output is correct
29 Correct 7 ms 468 KB Output is correct
30 Correct 8 ms 468 KB Output is correct
31 Correct 7 ms 468 KB Output is correct
32 Correct 7 ms 500 KB Output is correct
33 Correct 9 ms 468 KB Output is correct
34 Correct 7 ms 468 KB Output is correct
35 Correct 7 ms 468 KB Output is correct
36 Correct 7 ms 468 KB Output is correct
37 Correct 7 ms 468 KB Output is correct
38 Correct 8 ms 340 KB Output is correct
39 Correct 7 ms 468 KB Output is correct
40 Correct 9 ms 468 KB Output is correct
41 Correct 9 ms 340 KB Output is correct
42 Correct 7 ms 456 KB Output is correct
43 Correct 30 ms 11900 KB Output is correct
44 Incorrect 156 ms 53964 KB X_i is not increasing
45 Halted 0 ms 0 KB -