답안 #136385

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
136385 2019-07-25T08:12:23 Z dndhk Naan (JOI19_naan) C++14
100 / 100
779 ms 118244 KB
#include <bits/stdc++.h>

#define pb push_back
#define all(v) ((v).begin(), (v).end())
#define sortv(v) sort(all(v))
#define sz(v) ((int)(v).size())
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define umax(a, b) (a)=max((a), (b))
#define umin(a, b) (a)=min((a), (b))
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define rep(i,n) FOR(i,1,n)
#define rep0(i,n) FOR(i,0,(int)(n)-1)
#define FI first
#define SE second
#define INF 2000000000
#define INFLL 1000000000000000000LL


using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAX_N = 2000;

ll N, L;
ll arr[MAX_N+1][MAX_N+1];
ll sum[MAX_N+1];

vector<pll> vt[MAX_N+1];
bool vst[MAX_N+1];

vector<pll> ans;
vector<int> ans2;

bool calc(pll a, pll b){
	a.first; b.first;
	a.second /= N; b.second /= N;
	return (a.first * b.second > a.second * b.first);
}

int main(){
	scanf("%lld%lld", &N, &L);
	for(int i=1; i<=N; i++){
		for(int j=1; j<=L; j++){
			scanf("%lld", &arr[i][j]);
			sum[i]+=arr[i][j];
		}
		int now = 1;
		ll S = 0;
		for(int j=1; j<=L; j++){
			while(1){
				//cout<<S<<" "<<now<<endl;
				if((S+arr[i][j]) * N <= now * sum[i]){
					break;
				}
				pll p;
				p.first = sum[i] * now - S * N + (j-1) * N * arr[i][j];
				p.second = N * arr[i][j];
				vt[i].pb(p);
				//cout<<p.first<<" "<<p.second<<endl;
				now++;
			}
			S += arr[i][j];
		}
	}
	for(int i=0; i<N-1; i++){
		pll prv = {1, 0};
		int idx=0;
		for(int j=1; j<=N; j++){
			//cout<<prv.first<<" "<<prv.second<<" "<<vt[j][i].first<<" "<<vt[j][i].second<<endl;
			if(!vst[j] && calc(prv, vt[j][i])){
				idx = j; prv = vt[j][i];
			}
		}
		//cout<<idx<<endl;
		vst[idx] = true;
		ans.pb(prv);
		ans2.pb(idx);
	}
	for(int j=1; j<=N; j++){
		if(!vst[j]){
			ans2.pb(j);
			break;
		}
	}
	for(int i=0; i<ans.size(); i++){
		printf("%lld %lld\n", ans[i].first, ans[i].second);
	}
	for(int i=0; i<ans2.size(); i++){
		printf("%d ", ans2[i]);
	}
	return 0;
}

Compilation message

naan.cpp: In function 'bool calc(pll, pll)':
naan.cpp:37:4: warning: statement has no effect [-Wunused-value]
  a.first; b.first;
  ~~^~~~~
naan.cpp:37:13: warning: statement has no effect [-Wunused-value]
  a.first; b.first;
           ~~^~~~~
naan.cpp: In function 'int main()':
naan.cpp:87:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<ans.size(); i++){
               ~^~~~~~~~~~~
naan.cpp:90:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<ans2.size(); i++){
               ~^~~~~~~~~~~~
naan.cpp:43:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld", &N, &L);
  ~~~~~^~~~~~~~~~~~~~~~~~~~
naan.cpp:46:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%lld", &arr[i][j]);
    ~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 3 ms 508 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 3 ms 504 KB Output is correct
16 Correct 3 ms 504 KB Output is correct
17 Correct 3 ms 504 KB Output is correct
18 Correct 3 ms 504 KB Output is correct
19 Correct 3 ms 504 KB Output is correct
20 Correct 3 ms 504 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
22 Correct 3 ms 504 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 ms 380 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 3 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 3 ms 504 KB Output is correct
19 Correct 3 ms 504 KB Output is correct
20 Correct 3 ms 504 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 2 ms 380 KB Output is correct
24 Correct 3 ms 508 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 3 ms 504 KB Output is correct
34 Correct 3 ms 504 KB Output is correct
35 Correct 3 ms 504 KB Output is correct
36 Correct 3 ms 504 KB Output is correct
37 Correct 3 ms 504 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 3 ms 380 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 3 ms 504 KB Output is correct
43 Correct 62 ms 11896 KB Output is correct
44 Correct 362 ms 54352 KB Output is correct
45 Correct 220 ms 21240 KB Output is correct
46 Correct 32 ms 2424 KB Output is correct
47 Correct 264 ms 31324 KB Output is correct
48 Correct 304 ms 74976 KB Output is correct
49 Correct 97 ms 21752 KB Output is correct
50 Correct 457 ms 91628 KB Output is correct
51 Correct 234 ms 38008 KB Output is correct
52 Correct 475 ms 80164 KB Output is correct
53 Correct 376 ms 76280 KB Output is correct
54 Correct 3 ms 376 KB Output is correct
55 Correct 128 ms 44024 KB Output is correct
56 Correct 332 ms 52168 KB Output is correct
57 Correct 247 ms 49272 KB Output is correct
58 Correct 353 ms 78792 KB Output is correct
59 Correct 276 ms 46328 KB Output is correct
60 Correct 779 ms 117944 KB Output is correct
61 Correct 775 ms 118008 KB Output is correct
62 Correct 770 ms 117724 KB Output is correct
63 Correct 764 ms 118244 KB Output is correct
64 Correct 770 ms 118160 KB Output is correct
65 Correct 611 ms 104696 KB Output is correct
66 Correct 653 ms 104820 KB Output is correct
67 Correct 609 ms 104696 KB Output is correct
68 Correct 326 ms 60508 KB Output is correct
69 Correct 354 ms 56608 KB Output is correct
70 Correct 347 ms 72204 KB Output is correct
71 Correct 500 ms 82228 KB Output is correct