답안 #23055

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
23055 2017-05-02T14:18:51 Z model_code Kralj (COCI16_kralj) C++11
140 / 140
1089 ms 46204 KB
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

typedef pair<int, int> P;
#define X first
#define Y second

const int MAX = 500100;

int n;
int on[MAX];
int moji[MAX], poc[MAX];
int pref[MAX];
vector <int> V[MAX];

int rijesi(int prvi)
{
  int ret = 0;
  set <int> S;

  for (int i=prvi, j=0; j<n; j++, i=(i+1) % n) {
    for (auto it : V[i])
      S.insert(it);

    auto it = S.upper_bound(on[i]);
    if (it == S.end())
      S.erase(S.begin());
    else {
      ret++;
      S.erase(it);
    }
  }

  return ret;
}

int main()
{
  scanf("%d", &n);

  memset(pref, -1, sizeof pref);

  for (int i=0; i<n; i++) {
    scanf("%d", &poc[i]);
    poc[i]--;
  }

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

  for (int i=0; i<n; i++) {
    scanf("%d", &moji[i]);
    pref[poc[i]]++;
    V[poc[i]].push_back(moji[i]);
  }

  P minn = P(MAX, MAX);
  for (int i=0; i<n; i++) {
    if (i)
      pref[i] += pref[i-1];

    minn = min(minn, P(pref[i], i));
  }

  int prvi = (minn.Y + 1) % n;
  printf("%d\n", rijesi(prvi));

  return 0;
}

Compilation message

kralj.cpp: In function 'int main()':
kralj.cpp:44:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
                  ^
kralj.cpp:49:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &poc[i]);
                         ^
kralj.cpp:54:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &on[i]);
                        ^
kralj.cpp:57:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &moji[i]);
                          ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1089 ms 41584 KB Output is correct
2 Correct 739 ms 41056 KB Output is correct
3 Correct 923 ms 45676 KB Output is correct
4 Correct 936 ms 46204 KB Output is correct
5 Correct 549 ms 24012 KB Output is correct
6 Correct 473 ms 24408 KB Output is correct
7 Correct 569 ms 27048 KB Output is correct
8 Correct 486 ms 27180 KB Output is correct
9 Correct 596 ms 27180 KB Output is correct
10 Correct 556 ms 24804 KB Output is correct