Submission #1085308

# Submission time Handle Problem Language Result Execution time Memory
1085308 2024-09-07T23:29:43 Z 4QT0R Xylophone (JOI18_xylophone) C++17
0 / 100
1 ms 344 KB
#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;

void solve(int n){
	vector<int> zap(n+1);
	for (int i = 1; i<n; i++){
		zap[i]=query(i,i+1);
	}
	vector<int> ciag(n+1);
	ciag[1]=zap[1];
	for (int i = 2; i<n; i++){
		int q=query(i-1,i+1);
		if (zap[i-1]==q || zap[i]==q)ciag[i]=ciag[i-1]+zap[i]*(ciag[i-2]<ciag[i-1]?-1:1);
		else ciag[i]=ciag[i-1]+zap[i]*(ciag[i-2]<ciag[i-1]?1:-1);
	}
	int mn=1e9,mn_ind,mx=-1,mx_ind;
	for (int i = 0; i<n; i++){
		if (mn>ciag[i]){
			mn=ciag[i];
			mn_ind=i;
		}
		if (mx<ciag[i]){
			mx=ciag[i];
			mx_ind=i;
		}
	}
	if (mn_ind>mx_ind){
		for (int i = 0; i<n; i++)ciag[i]=-ciag[i];
		mn=-mn;
	}
	for (int i = 0; i<n; i++)answer(i+1,ciag[i]+mn+1);
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:28:2: warning: 'mn_ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
   28 |  if (mn_ind>mx_ind){
      |  ^~
xylophone.cpp:28:2: warning: 'mx_ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Incorrect 0 ms 344 KB Wrong Answer [4]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Incorrect 0 ms 344 KB Wrong Answer [4]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Incorrect 0 ms 344 KB Wrong Answer [4]
4 Halted 0 ms 0 KB -