Submission #333475

#TimeUsernameProblemLanguageResultExecution timeMemory
333475benson1029Xylophone (JOI18_xylophone)C++14
100 / 100
107 ms640 KiB
#include "xylophone.h"

#include<bits/stdc++.h>
using namespace std;

int rv1[5005],rv2[5005];
int sign[5005];
int a[5005];

void solve(int N) {
	for(int i=1; i<=N-1; i++) {
		rv1[i] = query(i, i+1);
	}
	for(int i=1; i<=N-2; i++) {
		rv2[i] = query(i, i+2);
	}
	for(sign[1] = 0; sign[1] <= 1; sign[1]++) {
		for(int i=1; i<=N-2; i++) {
			if(rv2[i] == rv1[i+1] + rv1[i]) {
				sign[i+1] = sign[i];
			} else {
				sign[i+1] = 1 - sign[i];
			}
		}
		a[1] = 0;
		int mn = 0;
		for(int i=2; i<=N; i++) {
			if(sign[i-1] == 0) a[i] = a[i-1] + rv1[i-1];
			else a[i] = a[i-1] - rv1[i-1];
			mn = min(mn, a[i]);
		}
		int pos1, posN;
		for(int i=1; i<=N; i++) {
			a[i] += (1-mn);
			if(a[i] == 1) pos1 = i;
			else if(a[i] == N) posN = i;
		}
		if(pos1 < posN) {
			for(int i=1; i<=N; i++) {
				answer(i, a[i]);
			}
			return;
		}
	}
}

Compilation message (stderr)

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:38:3: warning: 'posN' may be used uninitialized in this function [-Wmaybe-uninitialized]
   38 |   if(pos1 < posN) {
      |   ^~
xylophone.cpp:38:3: warning: 'pos1' 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...