답안 #232631

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
232631 2020-05-17T17:35:16 Z kshitij_sodani Xylophone (JOI18_xylophone) C++17
100 / 100
112 ms 632 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#include "xylophone.h"
/*void answer(int x,int y){
	cout<<x<<","<<y<<endl;
}
int query(int x,int y){
	cout<<x<<" "<<y<<endl;
	int yy;
	cin>>yy;
	return yy;
}*/
void solve(int n){
	if(n==1){
		answer(1,1);
		answer(2,2);
		return ;
	}
	int aa[n];
	for(int i=0;i<n-1;i++){
		aa[i]=query(i+1,i+2);
	}
	int bb[n];
	for(int i=0;i<n-2;i++){
		bb[i]=query(i+1,i+3);
	}
	int ans[n];
	ans[0]=0;
	int le=0;
	for(int i=0;i<n-1;i++){
		if(le==0){
			ans[i+1]=ans[i]+aa[i];
		}
		else{
			ans[i+1]=ans[i]-aa[i];
		}
		if(i<n-2){
			if(bb[i]==max(aa[i],aa[i+1])){
				le=1-le;
			}
		}
	}
	int mi;
/*	for(int i=0;i<n;i++){
		cout<<ans[i]<<" ";
	}
	cout<<endl;*/
	for(int i=0;i<n;i++){
		if(i==0){
			mi=ans[i];
		}
		else{
			mi=min(mi,ans[i]);
		}
	}
	int ind;
	int ind2;
	for(int i=0;i<n;i++){
		ans[i]+=(-mi+1);
		if(ans[i]==1){
			ind=i;
		}
		if(ans[i]==n){
			ind2=i;
		}
	}
	if(ind<ind2){
	//	cout<<11<<endl;
		for(int i=0;i<n;i++){
			answer(i+1,ans[i]);
		}
		return;
	}
	ans[0]=0;
	le=1;
	for(int i=0;i<n-1;i++){
		if(le==0){
			ans[i+1]=ans[i]+aa[i];
		}
		else{
			ans[i+1]=ans[i]-aa[i];
		}
		if(i<n-2){
			if(bb[i]==max(aa[i],aa[i+1])){
				le=1-le;
			}
		}
	}
	for(int i=0;i<n;i++){
		if(i==0){
			mi=ans[i];
		}
		else{
			mi=min(mi,ans[i]);
		}
	}
	for(int i=0;i<n;i++){
		ans[i]+=(-mi+1);
		if(ans[i]==1){
			ind=i;
		}
		if(ans[i]==n){
			ind2=i;
		}
	}
		for(int i=0;i<n;i++){
			answer(i+1,ans[i]);
		}
		return;


}
/*int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve(5);

	
	return 0;
}*/

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:73:2: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
  if(ind<ind2){
  ^~
xylophone.cpp:73:2: warning: 'ind2' may be used uninitialized in this function [-Wmaybe-uninitialized]
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 6 ms 256 KB Output is correct
4 Correct 6 ms 256 KB Output is correct
5 Correct 7 ms 384 KB Output is correct
6 Correct 7 ms 256 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 8 ms 384 KB Output is correct
11 Correct 6 ms 256 KB Output is correct
12 Correct 8 ms 256 KB Output is correct
13 Correct 8 ms 384 KB Output is correct
14 Correct 7 ms 256 KB Output is correct
15 Correct 7 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 6 ms 256 KB Output is correct
4 Correct 6 ms 256 KB Output is correct
5 Correct 7 ms 384 KB Output is correct
6 Correct 7 ms 256 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 8 ms 384 KB Output is correct
11 Correct 6 ms 256 KB Output is correct
12 Correct 8 ms 256 KB Output is correct
13 Correct 8 ms 384 KB Output is correct
14 Correct 7 ms 256 KB Output is correct
15 Correct 7 ms 384 KB Output is correct
16 Correct 9 ms 384 KB Output is correct
17 Correct 17 ms 256 KB Output is correct
18 Correct 25 ms 384 KB Output is correct
19 Correct 28 ms 256 KB Output is correct
20 Correct 28 ms 376 KB Output is correct
21 Correct 29 ms 384 KB Output is correct
22 Correct 23 ms 256 KB Output is correct
23 Correct 29 ms 384 KB Output is correct
24 Correct 20 ms 372 KB Output is correct
25 Correct 21 ms 384 KB Output is correct
26 Correct 24 ms 376 KB Output is correct
27 Correct 24 ms 372 KB Output is correct
28 Correct 25 ms 256 KB Output is correct
29 Correct 25 ms 384 KB Output is correct
30 Correct 24 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 6 ms 256 KB Output is correct
4 Correct 6 ms 256 KB Output is correct
5 Correct 7 ms 384 KB Output is correct
6 Correct 7 ms 256 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 8 ms 384 KB Output is correct
11 Correct 6 ms 256 KB Output is correct
12 Correct 8 ms 256 KB Output is correct
13 Correct 8 ms 384 KB Output is correct
14 Correct 7 ms 256 KB Output is correct
15 Correct 7 ms 384 KB Output is correct
16 Correct 9 ms 384 KB Output is correct
17 Correct 17 ms 256 KB Output is correct
18 Correct 25 ms 384 KB Output is correct
19 Correct 28 ms 256 KB Output is correct
20 Correct 28 ms 376 KB Output is correct
21 Correct 29 ms 384 KB Output is correct
22 Correct 23 ms 256 KB Output is correct
23 Correct 29 ms 384 KB Output is correct
24 Correct 20 ms 372 KB Output is correct
25 Correct 21 ms 384 KB Output is correct
26 Correct 24 ms 376 KB Output is correct
27 Correct 24 ms 372 KB Output is correct
28 Correct 25 ms 256 KB Output is correct
29 Correct 25 ms 384 KB Output is correct
30 Correct 24 ms 384 KB Output is correct
31 Correct 41 ms 384 KB Output is correct
32 Correct 61 ms 384 KB Output is correct
33 Correct 97 ms 504 KB Output is correct
34 Correct 91 ms 376 KB Output is correct
35 Correct 94 ms 384 KB Output is correct
36 Correct 107 ms 384 KB Output is correct
37 Correct 87 ms 376 KB Output is correct
38 Correct 87 ms 376 KB Output is correct
39 Correct 89 ms 384 KB Output is correct
40 Correct 112 ms 384 KB Output is correct
41 Correct 92 ms 488 KB Output is correct
42 Correct 91 ms 384 KB Output is correct
43 Correct 70 ms 508 KB Output is correct
44 Correct 93 ms 408 KB Output is correct
45 Correct 108 ms 504 KB Output is correct
46 Correct 109 ms 504 KB Output is correct
47 Correct 77 ms 384 KB Output is correct
48 Correct 73 ms 384 KB Output is correct
49 Correct 91 ms 428 KB Output is correct
50 Correct 98 ms 384 KB Output is correct
51 Correct 74 ms 396 KB Output is correct
52 Correct 77 ms 380 KB Output is correct
53 Correct 71 ms 632 KB Output is correct
54 Correct 75 ms 384 KB Output is correct
55 Correct 90 ms 380 KB Output is correct
56 Correct 94 ms 376 KB Output is correct
57 Correct 83 ms 384 KB Output is correct
58 Correct 77 ms 384 KB Output is correct
59 Correct 86 ms 504 KB Output is correct
60 Correct 86 ms 384 KB Output is correct