Submission #58567

# Submission time Handle Problem Language Result Execution time Memory
58567 2018-07-18T08:21:54 Z YaDon4ick Xylophone (JOI18_xylophone) C++14
47 / 100
77 ms 700 KB
//By Don4ick
//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
#include "xylophone.h"


typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qwer1234

const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};

using namespace std;


void solve(int n) {
	int pos = -1;
	int cnt = 0;
	//~binary_search
	{
		int l = 0, r = n + 1;
		while(l < r - 1)
		{
			int mid = (l + r) >> 1;
			cnt++;
			if (query(mid, n) == n - 1)
				l = mid;
			else
				r = mid;			
		}
		pos = l;
	}
	answer(pos, 1);
	//~solve(1, pos)
	if (pos > 1)
	{	
		cnt++;
		int y = 1, x = query(pos - 1, pos) + 1;
		answer(pos - 1, x);
		for (int i = pos - 2; i >= 1; i--)
		{
			cnt++;
			assert(cnt <= 10000);
			int value = query(i, i + 2);
			if (value > abs(x - y))
			{
				cnt++;
				assert(cnt <= 10000);
				int newValue = query(i, i + 1);
				if (x < y)
				{
					if (newValue == value)
					{
						y = x + value;
						swap(x, y);
						answer(i, x);
					}
					else
					{
						y = x - newValue;
						swap(x, y);
						answer(i, x);
					}
				}				
				else
				{
					if (newValue == value)
					{
						y = x - value;
						swap(x, y);
						answer(i, x);
					}
					else
					{
						y = x + newValue;
						swap(x, y);
						answer(i, x);
					}
				}
			}
			else
			{
				cnt++;
				assert(cnt <= 10000);
				int newValue = query(i, i + 1);			
				if (x < y)
				{
					y = x + newValue;
					swap(x, y);
					answer(i, x);	
				}
				else
				{
					y = x - newValue;
					swap(x, y);
					answer(i, x);
				}
			}
		} 
	}
	//~solve(pos, n)
	if (pos < n)
	{
		cnt++;
		assert(cnt <= 10000);	
		int y = 1, x = query(pos, pos + 1) + 1;
		answer(pos + 1, x);		
		for (int i = pos + 2; i <= n; i++)
		{
			cnt++;
			assert(cnt <= 10000);
			int value = query(i - 2, i);
			if (value > abs(x - y))
			{
				cnt++;
				assert(cnt <= 10000);
				int newValue = query(i - 1, i);
				if (x < y)
				{
					if (newValue == value)
					{
						y = x + value;
						swap(x, y);
						answer(i, x);
					}
					else
					{
						y = x - newValue;
						swap(x, y);
						answer(i, x);
					}
				}				
				else
				{
					if (newValue == value)
					{
						y = x - value;
						swap(x, y);
						answer(i, x);
					}
					else
					{
						y = x + newValue;
						swap(x, y);
						answer(i, x);
					}
				}
			}
			else
			{
				cnt++;
				assert(cnt <= 10000);
				int newValue = query(i - 1, i);			
				if (x < y)
				{
					y = x + newValue;
					swap(x, y);
					answer(i, x);	
				}
				else
				{
					y = x - newValue;
					swap(x, y);
					answer(i, x);
				}
			}
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 292 KB Output is correct
2 Correct 2 ms 312 KB Output is correct
3 Correct 3 ms 312 KB Output is correct
4 Correct 3 ms 368 KB Output is correct
5 Correct 4 ms 452 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 6 ms 504 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 4 ms 504 KB Output is correct
12 Correct 4 ms 504 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 5 ms 504 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 292 KB Output is correct
2 Correct 2 ms 312 KB Output is correct
3 Correct 3 ms 312 KB Output is correct
4 Correct 3 ms 368 KB Output is correct
5 Correct 4 ms 452 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 6 ms 504 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 4 ms 504 KB Output is correct
12 Correct 4 ms 504 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 5 ms 504 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
16 Correct 5 ms 504 KB Output is correct
17 Correct 15 ms 504 KB Output is correct
18 Correct 19 ms 532 KB Output is correct
19 Correct 12 ms 532 KB Output is correct
20 Correct 26 ms 532 KB Output is correct
21 Correct 22 ms 532 KB Output is correct
22 Correct 25 ms 532 KB Output is correct
23 Correct 11 ms 532 KB Output is correct
24 Correct 25 ms 532 KB Output is correct
25 Correct 24 ms 532 KB Output is correct
26 Correct 26 ms 532 KB Output is correct
27 Correct 12 ms 532 KB Output is correct
28 Correct 25 ms 532 KB Output is correct
29 Correct 16 ms 532 KB Output is correct
30 Correct 19 ms 532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 292 KB Output is correct
2 Correct 2 ms 312 KB Output is correct
3 Correct 3 ms 312 KB Output is correct
4 Correct 3 ms 368 KB Output is correct
5 Correct 4 ms 452 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 6 ms 504 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 4 ms 504 KB Output is correct
12 Correct 4 ms 504 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 5 ms 504 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
16 Correct 5 ms 504 KB Output is correct
17 Correct 15 ms 504 KB Output is correct
18 Correct 19 ms 532 KB Output is correct
19 Correct 12 ms 532 KB Output is correct
20 Correct 26 ms 532 KB Output is correct
21 Correct 22 ms 532 KB Output is correct
22 Correct 25 ms 532 KB Output is correct
23 Correct 11 ms 532 KB Output is correct
24 Correct 25 ms 532 KB Output is correct
25 Correct 24 ms 532 KB Output is correct
26 Correct 26 ms 532 KB Output is correct
27 Correct 12 ms 532 KB Output is correct
28 Correct 25 ms 532 KB Output is correct
29 Correct 16 ms 532 KB Output is correct
30 Correct 19 ms 532 KB Output is correct
31 Correct 38 ms 532 KB Output is correct
32 Correct 77 ms 532 KB Output is correct
33 Correct 63 ms 532 KB Output is correct
34 Runtime error 67 ms 700 KB Execution killed with signal 11 (could be triggered by violating memory limits)
35 Halted 0 ms 0 KB -