Submission #470823

# Submission time Handle Problem Language Result Execution time Memory
470823 2021-09-05T20:58:35 Z ali_tavakoli Xylophone (JOI18_xylophone) C++14
0 / 100
1 ms 200 KB
#include "xylophone.h"
//In The Name Of Allah
#include<bits/stdc++.h>
// using namespace std;
//
// typedef long long ll;
// #define pb push_back
// #define F first
// #define S second
// //#pragma GCC optimize("Ofast")
//
// const int maxn = 1e5 + 5;

static int a[5002], Used[5002], n;
std::map<std::pair<int, int> , int> mp;

int qr(int x, int y)
{
	if(mp.count({x, y}))
		return mp[{x, y}];
	else
		return mp[{x, y}] = query(x, y);
}

bool check()
{
	std::set<int> st;
	for(int i = 1; i <= n; i++)
	{
		st.insert(a[i]);
		if(a[i] == n&& !st.count(1))
			return false;
	}
	if(st.size() == n&& *st.end() == n)
		return true;
	return false;
}

void solve(int N)
{
	n = N;
	a[1] = 1;
	a[2] = 1 + qr(1, 2);
	int mn = 1;
	int now = 1;
	for(int i = 3; i <= N; i++)
	{
		if(qr(i - 2, i) != qr(i - 1, i))
			a[i] = a[i - 1] + qr(i - 1, i) * now;
		else
		{
			now = -now;
			a[i] = a[i - 1] + qr(i - 1, i) * now;
		}
		mn = std::min(mn, a[i]);
	}
	for(int i = 1; i <= N; i++)
	{
		a[i] += (1 - mn);
		//std::cout << a[i] << " ";
	}
	if(check())
	{
		for(int i = 1; i <= N; i++)
	  {
			std::cout << "ans : " << i << " " << a[i] << '\n';
			answer(i, a[i]);
		}
		//std::cout << "BOOOM\n";
	}
	else
	{
		a[1] = 1;
		a[2] = 1 - qr(1, 2);
		mn = a[2];
		now = -1;
		for(int i = 3; i <= N; i++)
		{
			if(qr(i - 2, i) != qr(i - 1, i))
				a[i] = a[i - 1] + qr(i - 1, i) * now;
			else
			{
				now = -now;
				a[i] = a[i - 1] + qr(i - 1, i) * now;
			}
			mn = std::min(mn, a[i]);
			//mx = std::max(mx, a[i]);
		}

		// for(int i = 1; i <= N; i++)
		// 	 std::cout << "ans : " << i << " " << a[i] << '\n';
		for(int i = 1; i <= N; i++)
		{
			a[i] += (1 - mn);
			//std::cout << a[i] << " ";
		}

		for(int i = 1; i <= N; i++)
			 answer(i, a[i]);
	}
}
//
// int main()
// {
// 	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//
// }

Compilation message

xylophone.cpp: In function 'bool check()':
xylophone.cpp:34:15: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   34 |  if(st.size() == n&& *st.end() == n)
      |     ~~~~~~~~~~^~~~
xylophone.cpp: At global scope:
xylophone.cpp:14:21: warning: 'Used' defined but not used [-Wunused-variable]
   14 | static int a[5002], Used[5002], n;
      |                     ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 200 KB Expected integer, but "ans" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 200 KB Expected integer, but "ans" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 200 KB Expected integer, but "ans" found
2 Halted 0 ms 0 KB -