답안 #370036

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
370036 2021-02-23T02:45:19 Z azberjibiou Naan (JOI19_naan) C++17
100 / 100
484 ms 117516 KB
#include <bits/stdc++.h>
#define gibon ios::sync_with_stdio(false); cin.tie(0);
using namespace std;
#define fir first
#define sec second
#define ll long long
#define pii pair<int, int>
const int mxN=2020;
typedef struct frac{
    ll ja, mo;
}frac;
ll N, L;
ll V[mxN][mxN];
frac ans[mxN][mxN];
ll sum[mxN];
bool Chk[mxN];
queue <int> que;
bool cmp(frac a, frac b)
{
  	ll anum=a.ja/a.mo, bnum=b.ja/b.mo;
    if(anum!=bnum)	return anum<bnum;
    a.ja-=anum*a.mo, b.ja-=bnum*b.mo;
    return a.ja*b.mo<b.ja*a.mo;
}
int main()
{
    gibon
    cin >> N >> L;
    for(int i=1;i<=N;i++)   for(int j=1;j<=L;j++)   cin >> V[i][j];
    for(int i=1;i<=N;i++)   for(int j=1;j<=L;j++)   sum[i]+=V[i][j];
    for(int i=1;i<=N;i++)
    {
        ll now=0;
        ll cnt=1;
        for(int j=1;j<=N;j++)
        {
            ll tot=sum[i];
            while(tot>N*V[i][cnt]-now)
            {
                tot-=N*V[i][cnt]-now;
                now=0;
                cnt++;
            }
            now+=tot;
            ans[i][j].mo=N*V[i][cnt];
            ans[i][j].ja=now+ans[i][j].mo*(cnt-1);
        }
    }
    for(int i=1;i<N;i++)
    {
        int pos=-1;
        for(int j=1;j<=N;j++)
        {
            if(Chk[j])  continue;
            if(pos==-1) pos=j;
            else if(cmp(ans[j][i], ans[pos][i]))    pos=j;
        }
        cout << ans[pos][i].ja << " " << ans[pos][i].mo << '\n';
        que.push(pos);
        Chk[pos]=true;
    }
    for(int i=1;i<=N;i++)    if(!Chk[i]) que.push(i);
    while(!que.empty())
    {
        cout << que.front() << " ";
        que.pop();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 1 ms 492 KB Output is correct
32 Correct 1 ms 492 KB Output is correct
33 Correct 1 ms 492 KB Output is correct
34 Correct 1 ms 492 KB Output is correct
35 Correct 1 ms 492 KB Output is correct
36 Correct 1 ms 492 KB Output is correct
37 Correct 1 ms 492 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 492 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 492 KB Output is correct
43 Correct 34 ms 11884 KB Output is correct
44 Correct 235 ms 54112 KB Output is correct
45 Correct 157 ms 21484 KB Output is correct
46 Correct 19 ms 2924 KB Output is correct
47 Correct 155 ms 34528 KB Output is correct
48 Correct 133 ms 73964 KB Output is correct
49 Correct 52 ms 23020 KB Output is correct
50 Correct 259 ms 90604 KB Output is correct
51 Correct 146 ms 41708 KB Output is correct
52 Correct 280 ms 87276 KB Output is correct
53 Correct 219 ms 81004 KB Output is correct
54 Correct 1 ms 492 KB Output is correct
55 Correct 56 ms 44012 KB Output is correct
56 Correct 180 ms 56596 KB Output is correct
57 Correct 141 ms 49388 KB Output is correct
58 Correct 191 ms 78700 KB Output is correct
59 Correct 172 ms 46288 KB Output is correct
60 Correct 484 ms 117356 KB Output is correct
61 Correct 453 ms 117228 KB Output is correct
62 Correct 460 ms 116864 KB Output is correct
63 Correct 459 ms 117516 KB Output is correct
64 Correct 452 ms 117356 KB Output is correct
65 Correct 357 ms 104044 KB Output is correct
66 Correct 353 ms 104044 KB Output is correct
67 Correct 356 ms 103916 KB Output is correct
68 Correct 177 ms 60268 KB Output is correct
69 Correct 205 ms 56684 KB Output is correct
70 Correct 199 ms 72172 KB Output is correct
71 Correct 299 ms 82412 KB Output is correct