답안 #498616

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
498616 2021-12-25T19:17:40 Z IOI_champion_in_1980 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
0 / 100
3000 ms 1400 KB
#include <bits/stdc++.h>
#include <math.h>
typedef long long ll;
using namespace std;
ll i, j, t, a, n, m, b, c, d, f, g;
int x[100100], y[100100];
void quickSort(int *array, int low, int high)
{
	int i=low;int j=high;int pivot=array[(i + j)/2];int temp;while(i<=j){while(array[i]<pivot)i++;while(array[j]>pivot)j--;
	if(i<=j){temp=array[i];array[i]=array[j];array[j]=temp;i++;j--;}}if(j>low)quickSort(array,low,j);if(i<high)quickSort(array,i,high);
}
int binarySearch(int array[], int x, int low, int high)
{
	while(low<=high){int mid=low+(high-low)/2;if(array[mid]==x)return mid;
	if(array[mid]<x)low=mid+1;else high=mid-1;}return -1;
}
int main()
{
    ios::sync_with_stdio(0);
	cin.tie(0);

	cin>>n>>m;
	for (a=1; a<=n; a++) cin>>x[a];
	for (a=1; a<=m; a++)
	{
		int l, r, k;
		cin>>l>>r>>k;
		int ans=1;
		for (b=l; b<=r; b++) y[b-l+1]=x[b];
		for (b=(r-l)+1; b>=2; b=b-2)
		{
			int mmax1=y[b], mmax2=y[b-1];
			int p1=b, p2=b-1;
			int r=0;
			for (c=b; c>=1; c--)
			{
				if (y[c]>mmax1)
				{
					r=1;
					mmax2=mmax1;
					mmax1=y[c];
					p2=p1;
					p1=c;
				}
			}
			if (y[p1]+y[p2]>k)
			{
				ans=0;
				break;
			}
			if (r==0) swap(y[b], y[b-1]);
			else
			{
				swap(y[b], y[p1]);
				swap(y[b-1], y[p2]);
			}
//			for (c=1; c<=n; c++) cout<<y[c]<<" ";
//			cout<<endl;
		}
		cout<<ans<<endl;
	}
}
/*

*/


Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:32:20: warning: variable 'mmax2' set but not used [-Wunused-but-set-variable]
   32 |    int mmax1=y[b], mmax2=y[b-1];
      |                    ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 14 ms 1400 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3023 ms 1160 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -