Submission #64607

# Submission time Handle Problem Language Result Execution time Memory
64607 2018-08-05T03:38:10 Z zscoder Xylophone (JOI18_xylophone) C++17
100 / 100
451 ms 992 KB
#include "xylophone.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

static int D[5111];
static int D2[5111];
static int change[5111];

int ask(int l, int r)
{
	l++; r++;
	return query(l,r);
}

void out(vector<int> &v)
{
	for(int i=0;i<v.size();i++)
	{
		answer(i+1,v[i]+1);
	}
}

bool valid(vector<int> &v)
{
	bool ok=0;
	for(int i=0;i<v.size();i++)
	{
		if(v[i]==0) ok=1;
		if(!ok&&v[i]==int(v.size())-1) return false;
		if(v[i]<0||v[i]>=int(v.size())) return false;
	}
	return true;
}

void solve(int N) 
{
	vector<int> A(N);
	for(int i=0;i+1<N;i++)
	{
		D[i] = ask(i,i+1);
		if(i+2<N) D2[i] = ask(i,i+2);
	}
	for(int i=2;i<N;i++)
	{
		if(D[i-2]+D[i-1]==D2[i-2])
		{
			change[i] = 0;
		}
		else
		{
			change[i] = 1;
		}
	}
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<2;j++)
		{
			vi V(N);
			V[0] = i; int cur = j;
			for(int k=1;k<N;k++)
			{
				if(cur) V[k]=V[k-1]+D[k-1];
				else V[k]=V[k-1]-D[k-1];
				if(k+1<N&&change[k+1]) cur^=1;
			}
			if(valid(V)) {out(V); return ;}
		}
	}
}

Compilation message

xylophone.cpp: In function 'void out(std::vector<int>&)':
xylophone.cpp:32:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<v.size();i++)
              ~^~~~~~~~~
xylophone.cpp: In function 'bool valid(std::vector<int>&)':
xylophone.cpp:41:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<v.size();i++)
              ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 312 KB Output is correct
3 Correct 4 ms 512 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 6 ms 512 KB Output is correct
6 Correct 6 ms 512 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 4 ms 552 KB Output is correct
9 Correct 3 ms 564 KB Output is correct
10 Correct 5 ms 564 KB Output is correct
11 Correct 5 ms 568 KB Output is correct
12 Correct 1 ms 568 KB Output is correct
13 Correct 4 ms 568 KB Output is correct
14 Correct 8 ms 568 KB Output is correct
15 Correct 5 ms 568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 312 KB Output is correct
3 Correct 4 ms 512 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 6 ms 512 KB Output is correct
6 Correct 6 ms 512 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 4 ms 552 KB Output is correct
9 Correct 3 ms 564 KB Output is correct
10 Correct 5 ms 564 KB Output is correct
11 Correct 5 ms 568 KB Output is correct
12 Correct 1 ms 568 KB Output is correct
13 Correct 4 ms 568 KB Output is correct
14 Correct 8 ms 568 KB Output is correct
15 Correct 5 ms 568 KB Output is correct
16 Correct 8 ms 568 KB Output is correct
17 Correct 12 ms 696 KB Output is correct
18 Correct 29 ms 696 KB Output is correct
19 Correct 36 ms 704 KB Output is correct
20 Correct 33 ms 704 KB Output is correct
21 Correct 39 ms 704 KB Output is correct
22 Correct 36 ms 716 KB Output is correct
23 Correct 30 ms 716 KB Output is correct
24 Correct 34 ms 716 KB Output is correct
25 Correct 13 ms 716 KB Output is correct
26 Correct 37 ms 716 KB Output is correct
27 Correct 31 ms 716 KB Output is correct
28 Correct 32 ms 716 KB Output is correct
29 Correct 19 ms 716 KB Output is correct
30 Correct 36 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 312 KB Output is correct
3 Correct 4 ms 512 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 6 ms 512 KB Output is correct
6 Correct 6 ms 512 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 4 ms 552 KB Output is correct
9 Correct 3 ms 564 KB Output is correct
10 Correct 5 ms 564 KB Output is correct
11 Correct 5 ms 568 KB Output is correct
12 Correct 1 ms 568 KB Output is correct
13 Correct 4 ms 568 KB Output is correct
14 Correct 8 ms 568 KB Output is correct
15 Correct 5 ms 568 KB Output is correct
16 Correct 8 ms 568 KB Output is correct
17 Correct 12 ms 696 KB Output is correct
18 Correct 29 ms 696 KB Output is correct
19 Correct 36 ms 704 KB Output is correct
20 Correct 33 ms 704 KB Output is correct
21 Correct 39 ms 704 KB Output is correct
22 Correct 36 ms 716 KB Output is correct
23 Correct 30 ms 716 KB Output is correct
24 Correct 34 ms 716 KB Output is correct
25 Correct 13 ms 716 KB Output is correct
26 Correct 37 ms 716 KB Output is correct
27 Correct 31 ms 716 KB Output is correct
28 Correct 32 ms 716 KB Output is correct
29 Correct 19 ms 716 KB Output is correct
30 Correct 36 ms 716 KB Output is correct
31 Correct 67 ms 716 KB Output is correct
32 Correct 129 ms 716 KB Output is correct
33 Correct 150 ms 828 KB Output is correct
34 Correct 328 ms 828 KB Output is correct
35 Correct 328 ms 828 KB Output is correct
36 Correct 122 ms 828 KB Output is correct
37 Correct 206 ms 828 KB Output is correct
38 Correct 89 ms 828 KB Output is correct
39 Correct 135 ms 836 KB Output is correct
40 Correct 213 ms 836 KB Output is correct
41 Correct 246 ms 836 KB Output is correct
42 Correct 66 ms 836 KB Output is correct
43 Correct 238 ms 836 KB Output is correct
44 Correct 158 ms 836 KB Output is correct
45 Correct 223 ms 836 KB Output is correct
46 Correct 323 ms 860 KB Output is correct
47 Correct 285 ms 860 KB Output is correct
48 Correct 141 ms 860 KB Output is correct
49 Correct 258 ms 860 KB Output is correct
50 Correct 287 ms 860 KB Output is correct
51 Correct 171 ms 860 KB Output is correct
52 Correct 114 ms 860 KB Output is correct
53 Correct 451 ms 992 KB Output is correct
54 Correct 342 ms 992 KB Output is correct
55 Correct 363 ms 992 KB Output is correct
56 Correct 435 ms 992 KB Output is correct
57 Correct 258 ms 992 KB Output is correct
58 Correct 357 ms 992 KB Output is correct
59 Correct 269 ms 992 KB Output is correct
60 Correct 300 ms 992 KB Output is correct