제출 #83635

#제출 시각아이디문제언어결과실행 시간메모리
83635wjoaoKralj (COCI16_kralj)C++11
140 / 140
804 ms43436 KiB
#include<bits/stdc++.h>
#define maxn 500010
using namespace std;

int n, dwarves[maxn], a, elves[maxn], sobras[maxn];
vector<int> f[maxn];

int main(){
  scanf(" %d", &n);
  for(int i = 1; i <= n; i++){
    scanf(" %d", &a);
    f[a].push_back(i);
  }

  for(int i = 1; i <= n; i++) scanf(" %d", &dwarves[i]);

  for(int i = 1; i <= n; i++) scanf(" %d", &elves[i]);

  for(int k = 0, j = 1, sobra = 0; k < 3*n; k++, j++, sobra--){
    if( j == n+1 ) j = 1;
    sobra = max(0, sobra);
    sobras[j] = max(sobra, sobras[j]);
    sobra += f[j].size();
  }

  int start_point;
  for(int i = 1; i <= n; i++){
    if(sobras[i] == 0){
      start_point = i;
      break;
    }
  }

  int vitorias = 0;
  int j = start_point;
  set<int> pokemon;
  while(true){
    for(int k = 0; k < f[j].size(); k++){
      pokemon.insert(elves[f[j][k]]);
    }
    set<int>::iterator it = pokemon.upper_bound(dwarves[j]);
    if(it == pokemon.end()){
      it = pokemon.begin();
    }
    if( *it > dwarves[j]) {
      vitorias++;
    }
    pokemon.erase(it);
    j++;
    if( j == n+1 ) j = 1;
    if( j == start_point ) break;
  }


  printf("%d\n", vitorias);
  return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

kralj.cpp: In function 'int main()':
kralj.cpp:38:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int k = 0; k < f[j].size(); k++){
                    ~~^~~~~~~~~~~~~
kralj.cpp:9:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %d", &n);
   ~~~~~^~~~~~~~~~~
kralj.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf(" %d", &a);
     ~~~~~^~~~~~~~~~~
kralj.cpp:15:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for(int i = 1; i <= n; i++) scanf(" %d", &dwarves[i]);
                               ~~~~~^~~~~~~~~~~~~~~~~~~~
kralj.cpp:17:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for(int i = 1; i <= n; i++) scanf(" %d", &elves[i]);
                               ~~~~~^~~~~~~~~~~~~~~~~~
kralj.cpp:51:5: warning: 'start_point' may be used uninitialized in this function [-Wmaybe-uninitialized]
     if( j == start_point ) break;
     ^~
#Verdict Execution timeMemoryGrader output
Fetching results...