답안 #919945

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
919945 2024-02-01T22:55:22 Z Lalic 코끼리 (Dancing Elephants) (IOI11_elephants) C++17
0 / 100
2 ms 8536 KB
#include <bits/stdc++.h>
#include "elephants.h"
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 15e4+10;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9+7;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int arr[MAXN], proc[MAXN];
int l, n;

void init(int N, int L, int X[])
{
	for(int i=0;i<N;i++) arr[i]=X[i], proc[i]=X[i];
	l=L; n=N;
}

int update(int i, int y)
{
	int id;
	for(int j=0;j<n;j++){
		if(proc[j]==arr[i]){
			id=j;
			break;
		}
	}
	
	int val=proc[id];
	
	if(val>y){
		bool foi=0;
		for(int j=id-1;j>=0;j--){
			proc[j+1]=proc[j];
			if(proc[j]<y){
				proc[j+1]=y;
				foi=1;
				break;
			}
		}
		if(!foi) proc[0]=y;
	}
	else{
		bool foi=0;
		for(int j=id+1;j<n;j++){
			proc[j-1]=proc[j];
			if(proc[j]>y){
				proc[j-1]=y;
				foi=1;
				break;
			}
		}
		if(!foi) proc[n-1]=y;
	}
	
	int ans=0, curr=-l-1;
	for(int j=0;j<n;j++){
		if(proc[j]<=curr+l) continue;
		ans++;
		curr=proc[j];
	}
	
	return ans;
}

Compilation message

elephants.cpp: In function 'int update(int, int)':
elephants.cpp:42:6: warning: 'id' may be used uninitialized in this function [-Wmaybe-uninitialized]
   42 |  int val=proc[id];
      |      ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 8536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 8536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 8536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 8536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 8536 KB Output isn't correct
2 Halted 0 ms 0 KB -