Submission #1116814

# Submission time Handle Problem Language Result Execution time Memory
1116814 2024-11-22T12:22:09 Z mmk Xylophone (JOI18_xylophone) C++17
0 / 100
4 ms 336 KB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
int a[5000];
map<pair<int,int>,int> marc;

int q(int ini, int fim)
{
	if(!marc[{ini,fim}]) return marc[{ini,fim}] = query(ini,fim);
	else return marc[{ini,fim}];
}

void solve(int N)
{
	a[1] = 0;
	a[2] = a[1] + q(1,2);

	int menor = 2*N, maior = -2*N;
	int minPos = 0, maxPos = 0;

	for(int i = 2; i < N; i++)
	{
		int d12 = q(i-1,i);
		int d23 = q(i,i+1);
		int d13 = q(i-1,i+1);
		int sign = (a[i] - a[i-1])/d12;

		if(d13 == d12 + d23)
			a[i+1] = a[i-1] + sign*(d13);
		else
			a[i+1] = a[i] - sign*(d23);


	}

	for(int i = 1; i <= N; i++)
	{
		if(a[i] < menor)
		{
			menor = a[i];
			minPos = i;
		}

		if(a[i] > maior)
		{
			maior = a[i];
			maxPos = i;
		}
	}

	int dif = 1 - menor;

	if(minPos < maxPos)
	{
		for(int i = 1; i <= N; i++)
			answer(i,a[i] + dif);
	}
	else
	{
		for(int i = N; i >= 1; i--)
			answer(i,a[i] + dif);
	}

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 4 ms 336 KB Output is correct
5 Incorrect 4 ms 336 KB Wrong Answer [7]
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 4 ms 336 KB Output is correct
5 Incorrect 4 ms 336 KB Wrong Answer [7]
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 4 ms 336 KB Output is correct
5 Incorrect 4 ms 336 KB Wrong Answer [7]
6 Halted 0 ms 0 KB -