답안 #1116607

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1116607 2024-11-22T01:43:21 Z gustavo_d Xylophone (JOI18_xylophone) C++17
0 / 100
2 ms 336 KB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;

static int A[5000];
int a[5000];

void solve(int N) {
	int n = N;
	int pos1=n;
	for (; pos1>=1; pos1--) {
		int value = query(pos1, n);
		if (value == n-1) break;
	}
	a[pos1] = 1;
	int last = 1;
	int nxt = query(pos1, pos1+1) + 1;
	a[pos1+1] = nxt;
	for (int pt = pos1+2; pt<=n; pt++) {
		int d1 = a[pt-1] - a[pt-2];
		int d = query(pt-1, pt);
		if (a[pt-2] < a[pt-1]) {
			if (query(pt-2, pt) == d + d1) a[pt] = a[pt-1] + d;
			else a[pt] = a[pt-1] - d;
		} else {
			if (query(pt-2, pt) == d + d1) a[pt] = a[pt-1] - d;
			else a[pt] = a[pt-1] + d;
		}
	}
	for (int pt = pos1-1; pt>=1; pt--) {
		int d1 = a[pt+1] - a[pt+2];
		int d = query(pt, pt+1);
		if (a[pt+2] < a[pt+1]) {
			if (query(pt, pt+2) == d + d1) a[pt] = a[pt+1] + d;
			else a[pt] = a[pt-1] - d;
		} else {
			if (query(pt, pt+2) == d + d1) a[pt] = a[pt+1] - d;
			else a[pt] = a[pt+1] + d;
		}
	}

	for(int i = 1; i <= N; i++) {
		// cout << a[i] << ' ';
		answer(i, a[i]);
	}
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:16:6: warning: unused variable 'last' [-Wunused-variable]
   16 |  int last = 1;
      |      ^~~~
xylophone.cpp: At global scope:
xylophone.cpp:5:12: warning: 'A' defined but not used [-Wunused-variable]
    5 | static int A[5000];
      |            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Incorrect 2 ms 336 KB Wrong Answer [4]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Incorrect 2 ms 336 KB Wrong Answer [4]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Incorrect 2 ms 336 KB Wrong Answer [4]
4 Halted 0 ms 0 KB -