답안 #533326

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
533326 2022-03-05T13:18:45 Z codr0 Naan (JOI19_naan) C++14
100 / 100
455 ms 116352 KB
// Code by Parsa Eslami
 
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define bit(i,j) ((j>>i)&1)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORR(i,a,b) for(int i=a;i>=b;i--)
#define S second
#define F first
#define pb push_back
#define SZ(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define err(x) cout<<#x<<": "<<x<<'\n';
 
using namespace std;

	pii simp(pii X){
		return X;
		int gc=__gcd(X.F,X.S);
		X.S/=gc;
		X.F/=gc;
		return X;
	}

	pii sum(pii a,pii b){// a+b
		pii rt;
		int gc=1;
		if(a.S==b.S) gc=a.S;
		rt.S=a.S*(b.S/gc);
		rt.F=a.F*(b.S/gc)+b.F*(a.S/gc);
		return rt;
	}

	pii mul(pii a,pii b){// a*b
		pii rt;
		rt.F=a.F*b.F;
		rt.S=a.S*b.S;
		if(a.S%b.F==0){
			rt.F=a.F;
			rt.S=b.S*(a.S/b.F);
		}
		else if(b.S%a.F==0){
			rt.F=b.F;
			rt.S=a.S*(b.S/a.F);
		}
		return rt;
	}

	pii L(pii a,pii b){// a-b
		b.F=-b.F;
		return sum(a,b);
	}

	pii div(pii a,pii b){// a/b
		swap(b.F,b.S);
		return mul(a,b);
	}

	bool cmp(pii a,pii b){// a<=b
		int A=a.F/a.S;
		int B=b.F/b.S;
		if(A!=B) return (A<B);
		a.F-=A*a.S;
		b.F-=B*b.S;
		return (a.F*b.S<=a.S*b.F);
	}

	int32_t main(){
	ios_base::sync_with_stdio(0); cin.tie(0);

	int n,l; cin>>n>>l;
	int v[n+1][l+1];
	FOR(i,1,n) FOR(j,1,l) cin>>v[i][j];
	pii a[n][n];
	FOR(i,1,n){
		pii point={0,1};//
		pii S={0,1};//
		int ind=1;//
		int Sp=0;
		FOR(j,1,l) Sp+=v[i][j];
		pii targ={Sp,n};
		FOR(j,1,n-1){
			while(1){
				pii l=div(L(targ,S),{v[i][ind],1});
				if(cmp(sum(l,point),{1,1})){
					a[i][j]=sum({ind-1,1},sum(l,point));
					point=sum(l,point);
					S={0,1};
					if(point.F==point.S){
						ind++;
						point={0,1};
					}
					break;
				}else{
					S=sum(S,mul(L({1,1},point),{v[i][ind],1}));
					ind++; point={0,1};
				}
			}
		}
	}
	bool mark[n+1]={};
	int p[n+1]={};
	FOR(i,1,n-1){
		pair<pii,int> ans={{1e9,1},-1};
		FOR(j,1,n) if(!mark[j]){
			pair<pii,int> x0={a[j][i],j};
			if(ans.S==-1||cmp(x0.F,ans.F)) ans=x0;
		}
		mark[ans.S]=1;
		p[i]=ans.S;
		cout<<ans.F.F<<" "<<ans.F.S<<'\n';
	}
	FOR(i,1,n) if(!mark[i]) p[n]=i;
	FOR(i,1,n) cout<<p[i]<<" "; cout<<'\n';


	return 0;
	}

Compilation message

naan.cpp: In function 'int32_t main()':
naan.cpp:7:20: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
    7 | #define FOR(i,a,b) for(int i=a;i<=b;i++)
      |                    ^~~
naan.cpp:115:2: note: in expansion of macro 'FOR'
  115 |  FOR(i,1,n) cout<<p[i]<<" "; cout<<'\n';
      |  ^~~
naan.cpp:115:30: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  115 |  FOR(i,1,n) cout<<p[i]<<" "; cout<<'\n';
      |                              ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 284 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 284 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 2 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 29 ms 7244 KB Output is correct
44 Correct 185 ms 43080 KB Output is correct
45 Correct 126 ms 17864 KB Output is correct
46 Correct 16 ms 1996 KB Output is correct
47 Correct 165 ms 26424 KB Output is correct
48 Correct 120 ms 62020 KB Output is correct
49 Correct 45 ms 15980 KB Output is correct
50 Correct 253 ms 86576 KB Output is correct
51 Correct 132 ms 34480 KB Output is correct
52 Correct 265 ms 78716 KB Output is correct
53 Correct 198 ms 67268 KB Output is correct
54 Correct 1 ms 332 KB Output is correct
55 Correct 47 ms 32636 KB Output is correct
56 Correct 164 ms 47868 KB Output is correct
57 Correct 137 ms 39596 KB Output is correct
58 Correct 181 ms 64956 KB Output is correct
59 Correct 153 ms 40644 KB Output is correct
60 Correct 428 ms 116100 KB Output is correct
61 Correct 444 ms 116048 KB Output is correct
62 Correct 438 ms 115560 KB Output is correct
63 Correct 455 ms 116352 KB Output is correct
64 Correct 436 ms 116228 KB Output is correct
65 Correct 336 ms 102852 KB Output is correct
66 Correct 342 ms 102948 KB Output is correct
67 Correct 357 ms 102908 KB Output is correct
68 Correct 169 ms 49144 KB Output is correct
69 Correct 196 ms 48964 KB Output is correct
70 Correct 194 ms 59564 KB Output is correct
71 Correct 285 ms 74820 KB Output is correct