Submission #312947

#TimeUsernameProblemLanguageResultExecution timeMemory
312947sofapudenXylophone (JOI18_xylophone)C++14
100 / 100
129 ms512 KiB
#include "xylophone.h"
#include <bits/stdc++.h>

using namespace std;

int A[5005];

void solve(int n) {
	A[1] = 0;
	A[2] = query(1,2);
	for(int i = 2; i < n; ++i){
		int a = query(i,i+1);
		int b = query(i-1,i+1);
		A[i+1] = A[i] + a*(A[i]-A[i-1] < 0 ? 1 : -1)*(b == a + abs(A[i]-A[i-1]) ? -1 : 1);
	}
	int mi = *min_element(A+1, A+1+n);
	int l, r;
	for(int i = 1; i <= n; ++i){
		A[i]-=mi;
		if(A[i] == 0)l = i;
		if(A[i] == n-1)r = i;
	}
	bool ok = l < r;
	for(int i = 1; i <= n; ++i)answer(i,ok ? A[i]+1 : n-A[i]);
}

Compilation message (stderr)

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:24:35: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
   24 |  for(int i = 1; i <= n; ++i)answer(i,ok ? A[i]+1 : n-A[i]);
      |                             ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
xylophone.cpp:24:35: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...