답안 #26971

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
26971 2017-07-07T16:31:06 Z repeating 코끼리 (Dancing Elephants) (IOI11_elephants) C++11
26 / 100
9000 ms 20800 KB
#include <bits/stdc++.h>
#include "elephants.h"
#define F first
#define S second
#define P push
#define pb push_back
#define MEM(dp,i) memset(dp,i,sizeof(dp))
#define W while
#define R return
#define C continue
#define SI size()
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define pii pair<int,int>
#define SF(x) scanf("%I64d",&x)
#define SF2(x,y) scanf("%I64d%I64d",&x,&y)
#define SF3(x,y,z) scanf("%I64d%I64d%I64d",&x,&y,&z)
#define SF4(x,y,z,o) scanf("%I64d%I64d%I64d%I64d",&x,&y,&z,&o)
#define all(v) v.begin(),v.end()
#define MAX_R  1000000
#define MAX_N 1000000
#define MAX_M 1000000

using namespace std;
const long long INF = 1e9+5e8;
const int MX=109;


int n;
vector<pii> v;
int l;
void init(int N, int L, int X[])
{
    l=L;
    n = N;
    for(int i=0;i<n;i++)
        v.pb({X[i],i});
}

int update(int x, int y)
{
    int ind;
    for(int i=0;i<v.SI;i++){
        if(v[i].S==x)ind=i;
    }
    v[ind].F=y;
    W(1){
        if((ind==0||v[ind-1].F<=v[ind].F)&&(ind==n-1||v[ind].F<=v[ind+1].F))break;
        if(!(ind==0||v[ind-1].F<=v[ind].F)){
            swap(v[ind],v[ind-1]);
            ind--;
        }
        else{
            swap(v[ind],v[ind+1]);
            ind++;
        }
    }
//    for(auto i : v)cout<<i.F<<" ";
//    cout<<endl;
    int last=0;
    int ret=1;
    for(int i=1;i<v.SI;i++){
        if(v[i].F-v[last].F>l){
            ret++;
            last=i;
        }
    }
    return ret;
}
//
//static int N,L,M;
//static int X[MAX_N];
//static int ii[MAX_M];
//static int yy[MAX_M];
//static int sol[MAX_M];
//
//inline
//void my_assert(int e) {if (!e) abort();}
//
//void read_input()
//{
//  int i;
//  my_assert(3==scanf("%d %d %d",&N,&L,&M));
//  for(i=0; i<N; i++)
//    my_assert(1==scanf("%d",&X[i]));
//  for(i=0; i<M; i++)
//    my_assert(3==scanf("%d %d %d",&ii[i],&yy[i],&sol[i]));
//}
//
//int main()
//{
//  int i, ans;
//
//  read_input();
//  init(N,L,X);
//  for(i=0; i<M; i++) {
//    ans = update(ii[i],yy[i]);
//    if(ans==sol[i])continue;
//      printf("Incorrect.  In %d-th move, answered %d (%d expected).\n",
//	     i+1, ans, sol[i]);
//    return 0;
//  }
//  printf("Correct.\n");
//  return 0;
//}

Compilation message

elephants.cpp: In function 'int update(int, int)':
elephants.cpp:44:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v.SI;i++){
                  ^
elephants.cpp:63:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=1;i<v.SI;i++){
                  ^
elephants.cpp:47:10: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
     v[ind].F=y;
          ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 17644 KB Output is correct
2 Correct 0 ms 17644 KB Output is correct
3 Correct 0 ms 17644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 17644 KB Output is correct
2 Correct 0 ms 17644 KB Output is correct
3 Correct 0 ms 17644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2876 ms 17916 KB Output is correct
2 Correct 4296 ms 18112 KB Output is correct
3 Correct 4078 ms 18496 KB Output is correct
4 Execution timed out 9000 ms 18496 KB Execution timed out
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4126 ms 18112 KB Output is correct
2 Correct 8003 ms 18112 KB Output is correct
3 Execution timed out 9000 ms 18496 KB Execution timed out
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 9000 ms 20800 KB Execution timed out
2 Halted 0 ms 0 KB -