답안 #244483

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
244483 2020-07-04T07:06:59 Z abacaba Kralj (COCI16_kralj) C++14
56 / 140
2000 ms 52968 KB
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;
 
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define emb emplace_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>

#define x1 ssfadsf
#define x2 asfadsfk
#define y1 bfgbdgb
#define y2 dfgsfdg
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template <typename T> inline T range(T l, T r) {
    return uniform_int_distribution<T>(l, r)(rng);
}
 
inline void setin(string s) {
    freopen(s.c_str(), "r", stdin);
}
 
inline void setout(string s) {
    freopen(s.c_str(), "w", stdout);
}
 
template <typename T> void Min(T &a, T b) {
    a = min(a, b);
}
 
template <typename T> void Max(T &a, T b) {
    a = max(a, b);
}

const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const int N = 5e5 + 15;
int n, m, a[N], b[N], c[N];
vector <int> ord[N];
multiset <int> cur;
int ans;

inline int solve(int start) {
    int ans = 0;
    cur.clear();
    for(int i = start; i <= n; ++i) {
        for(int j : ord[i])
            cur.insert(c[j]);
        multiset <int>::iterator it = cur.upper_bound(b[i]);
        if(it == cur.end()) {
            if(cur.empty())
                return 0;
            cur.erase(cur.begin());
        }
        else
            ++ans, cur.erase(it);
    }
    for(int i = 1; i < start; ++i) {
        for(int j : ord[i])
            cur.insert(c[j]);
        multiset <int>::iterator it = cur.upper_bound(b[i]);
        if(it == cur.end()) {
            if(cur.empty())
                return 0;
            cur.erase(cur.begin());
        }
        else
            ++ans, cur.erase(it);
    }
    return ans;
}

main() {
    ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
    // setin("input.txt");
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        ord[a[i]].pb(i);
    }
    for(int i = 1; i <= n; ++i)
        cin >> b[i];
    for(int i = 1; i <= n; ++i)
        cin >> c[i];
    for(int i = 1; i <= n; ++i)
        Max(ans, solve(i));
    cout << ans << endl;
    return 0;
}

Compilation message

kralj.cpp:104:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 738 ms 45800 KB Output is correct
2 Correct 468 ms 44488 KB Output is correct
3 Correct 726 ms 52456 KB Output is correct
4 Correct 735 ms 52968 KB Output is correct
5 Execution timed out 2062 ms 32376 KB Time limit exceeded
6 Execution timed out 2092 ms 32120 KB Time limit exceeded
7 Execution timed out 2098 ms 36088 KB Time limit exceeded
8 Execution timed out 2088 ms 34700 KB Time limit exceeded
9 Execution timed out 2025 ms 37496 KB Time limit exceeded
10 Execution timed out 2040 ms 33784 KB Time limit exceeded