답안 #498215

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
498215 2021-12-24T15:45:16 Z sireanu_vlad Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
0 / 100
500 ms 91252 KB
#include <iostream>
using namespace std;

int n, m, w[1000001], p, a[10001][10001];

void read()
{
	cin >> n >> m;
	for(int i = 1; i <= n; ++i)
		cin >> w[i];
}

void config()
{
	for(int i = 1; i <= n; ++i)
		for(int j = i+1; j <= n; ++j)
			a[i][j] = a[j][i] = w[i] + w[j];
}

bool mov(int id, int k, int l, int r)
{
	for(int i = l; i <= r; ++i)
	{
		if(i != id && a[i][id] <= k)
			return 1;
	}
	return 0;
}

bool solve(int l, int r, int k)
{
	int inv = 0;
	for(int i = l; i < r; ++i)
		for(int j = i+1; j <= r; ++j)
			inv += (w[i] > w[j]);

	if(inv == 0)
		return 1;

	for(int i = l; i <= r; ++i)
		if(w[i] >= k || !mov(i, k, l, r))
			return 0;

	for(int i = l; i <= r; ++i)
		for(int j = i+1; j <= r; ++j)
			if(a[i][j] <= k)
				inv--;
	return (inv <= 0);
}

int main()
{
	read();
	config();
	int l, r, k;
	while(m--)
	{
		cin >> l >> r >> k;
		cout << solve(l, r, k) << '\n';
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Incorrect 3 ms 844 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Incorrect 3 ms 844 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 500 ms 91252 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 160 ms 85076 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Incorrect 3 ms 844 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Incorrect 3 ms 844 KB Output isn't correct
4 Halted 0 ms 0 KB -