Submission #1013698

# Submission time Handle Problem Language Result Execution time Memory
1013698 2024-07-03T21:34:37 Z vjudge1 Xylophone (JOI18_xylophone) C++17
47 / 100
2000 ms 920 KB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
#define endl "\n"
const int mod=1e9+7;
#define OVL(x,s) for(auto y:x) cout<<y<<s; cout<<"\n";
template <typename T> istream& operator>>(istream& is, vector<T> &a) {
    copy_n(istream_iterator<T>(is), a.size(), a.begin()); return is;}
#ifdef IOI
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
 
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__);
#else
#define dbg(...) 1337;
#endif
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
const int mxn=2e5+100;
static int A[5000];
#ifdef IOI
static const int N_MAX = 5000;
static const int Q_MAX = 10000;
static int N;
static bool used[N_MAX];
static int query_c;
static int answer_c;
int query(int s, int t) {
	if(query_c >= Q_MAX) {
		printf("Wrong Answer\n");
		exit(0);
	}
	query_c++;
	if(!(1 <= s && s <= t && t <= N)) {
		printf("Wrong Answer\n");
		exit(0);
	}
	int mx = 0, mn = N + 1;
	for(int i = s - 1; i < t; i++) {
		if(mx < A[i]) {
			mx = A[i];
		}
		if(mn > A[i]) {
			mn = A[i];
		}
	}
	return mx - mn;
}

void answer(int i, int a) {
	answer_c++;
	if(!(1 <= i && i <= N)) {
		printf("Wrong Answer\n");
		exit(0);
	}
	if(!(1 <= a && a <= N)) {
		printf("Wrong Answer\n");
		exit(0);
	}
	if(used[i - 1]) {
		printf("Wrong Answer\n");
		exit(0);
	}
	if(a != A[i - 1]) {
		printf("Wrong Answer\n");
		exit(0);
	}
	used[i - 1] = true;
}
#endif
map<pair<int,int>,int> mp;
int q(int l,int r){
	if(mp.count({l,r})) return mp[{l,r}];
	return mp[{l,r}]=query(l,r);
}
vector<int> solve(int pos,int n){
	bool visited[n+1];
	vector<int> ans(n+1);
	memset(visited,false,sizeof(visited));
	ans[pos]=1;
	visited[1]=1;
	if(pos!=n){
		ans[pos+1]=q(pos,pos+1)+1;
		visited[ans[pos+1]]=1;
		for(int i=pos+2;i<=n;i++){
			int a=ans[i-2];
			int b=ans[i-1];
			int x=q(i-2,i);
			int y=q(i-1,i);
			bool fl=false;
			for(int c=1;c<=n;c++){
				if(visited[c]) continue;
				vector<int> v={a,b,c};
				sort(all(v));
				vector<int> t={b,c};
				sort(all(t));
				if(v[2]-v[0]==x&&t[1]-t[0]==y){
					ans[i]=c;
					visited[ans[i]]=1;
					fl=true;
					break;
				}
			}
			if(fl) continue;
			return {-1};
		}
	}
	if(pos!=1){
		ans[pos-1]=q(pos-1,pos)+1;
		for(int i=pos-2;i>=1;i--){
			int a=ans[i+2];
			int b=ans[i+1];
			int x=q(i,i+2);
			int y=q(i,i+1);
			bool fl=false;
			for(int c=1;c<=n;c++){
				if(visited[c]) continue;
				vector<int> v={a,b,c};
				sort(all(v));
				vector<int> t={b,c};
				sort(all(t));
				if(v[2]-v[0]==x&&t[1]-t[0]==y){
					ans[i]=c;
					visited[ans[i]]=1;
					fl=true;
					break;
				}
			}
			if(fl) continue;
			return {-1};
		}
	}
	return ans;
}
void solve(int N) {
	vector<int> ans;
	for(int i=1;i<=N;i++){
		ans=solve(i,N);
		if(ans.size()==1) continue;
		for(int i=1;i<=N;i++){
			answer(i,ans[i]);
		}
		return;
	}
	// dbg(ans)

}


#ifdef IOI
int main() {
	query_c = 0;
	answer_c = 0;
	if(scanf("%d", &N) != 1) {
		fprintf(stderr, "Error while reading input\n");
		exit(1);
	}
	for(int i = 0; i < N; i++) {
		if(scanf("%d", A + i) != 1) {
			fprintf(stderr, "Error while reading input\n");
			exit(1);
		}
		used[i] = false;
	}
	solve(N);
	if(!(answer_c == N)) {
		printf("Wrong Answer\n");
		exit(0);
	}
	printf("Accepted : %d\n", query_c);
}

#endif

Compilation message

xylophone.cpp:25:12: warning: 'A' defined but not used [-Wunused-variable]
   25 | static int A[5000];
      |            ^
# 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 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 3 ms 344 KB Output is correct
8 Correct 4 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 2 ms 344 KB Output is correct
13 Correct 1 ms 444 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
# 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 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 3 ms 344 KB Output is correct
8 Correct 4 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 2 ms 344 KB Output is correct
13 Correct 1 ms 444 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
16 Correct 3 ms 344 KB Output is correct
17 Correct 11 ms 344 KB Output is correct
18 Correct 20 ms 500 KB Output is correct
19 Correct 52 ms 600 KB Output is correct
20 Correct 100 ms 344 KB Output is correct
21 Correct 109 ms 776 KB Output is correct
22 Correct 68 ms 344 KB Output is correct
23 Correct 14 ms 476 KB Output is correct
24 Correct 57 ms 600 KB Output is correct
25 Correct 18 ms 344 KB Output is correct
26 Correct 127 ms 440 KB Output is correct
27 Correct 156 ms 592 KB Output is correct
28 Correct 50 ms 736 KB Output is correct
29 Correct 72 ms 688 KB Output is correct
30 Correct 78 ms 344 KB Output is correct
# 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 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 3 ms 344 KB Output is correct
8 Correct 4 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 2 ms 344 KB Output is correct
13 Correct 1 ms 444 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
16 Correct 3 ms 344 KB Output is correct
17 Correct 11 ms 344 KB Output is correct
18 Correct 20 ms 500 KB Output is correct
19 Correct 52 ms 600 KB Output is correct
20 Correct 100 ms 344 KB Output is correct
21 Correct 109 ms 776 KB Output is correct
22 Correct 68 ms 344 KB Output is correct
23 Correct 14 ms 476 KB Output is correct
24 Correct 57 ms 600 KB Output is correct
25 Correct 18 ms 344 KB Output is correct
26 Correct 127 ms 440 KB Output is correct
27 Correct 156 ms 592 KB Output is correct
28 Correct 50 ms 736 KB Output is correct
29 Correct 72 ms 688 KB Output is correct
30 Correct 78 ms 344 KB Output is correct
31 Correct 401 ms 920 KB Output is correct
32 Correct 901 ms 780 KB Output is correct
33 Execution timed out 2166 ms 756 KB Time limit exceeded
34 Halted 0 ms 0 KB -