답안 #623316

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
623316 2022-08-05T12:45:36 Z Awerar 최후의 만찬 (IOI12_supper) C++14
0 / 100
270 ms 34240 KB
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <limits.h>
#include <math.h>
#include <chrono>
#include <queue>
#include <stack>
#include <algorithm>
 
using namespace std;
 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
 
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define p2 pair<ll, ll>
#define p3 tuple<ll,ll,ll>
#define p4 vi
#define ip3 tuple<int,int,int>
#define ip4 tuple<int,int,int,int>
#define vp2 vector<p2>
#define vp3 vector<p3>
#define inf 2e9
#define linf 1e17
 
#define read(a) cin >> a
#define write(a) cout << (a) << "\n"
#define dread(type, a) type a; cin >> a
#define dread2(type, a, b) dread(type, a); dread(type, b)
#define dread3(type, a, b, c) dread2(type, a, b); dread(type, c)
#define dread4(type, a, b, c, d) dread3(type, a, b, c); dread(type, d)
#define dread5(type, a, b, c, d, e) dread4(type, a, b, c, d); dread(type, e)
#ifdef _DEBUG
#define deb __debugbreak();
#else
#define deb ;
#endif
 
#define rep(i, high) for (ll i = 0; i < high; i++)
#define repp(i, low, high) for (ll i = low; i < high; i++)
#define repe(i, container) for (auto& i : container)
#define per(i, high) for (ll i = high; i >= 0; i--)
 
#define readpush(type,vect) type temp; read(temp); vect.push_back(temp);
#define readvector(type, name, size) vector<type> name(size); rep(i,size) {dread(type,temp); name[i]=temp;}
#define readinsert(type,a) {type temp; read(temp); a.insert(temp);}
#define all(a) begin(a),end(a)
#define setcontains(set, x) (set.find(x) != set.end())
#define stringcontains(str, x) (str.find(x) != string::npos)
#define within(a, b, c, d) (a >= 0 && a < b && c >= 0 && c < d)
 
#define ceildiv(x,y) ((x + y - 1) / y)
#define fract(a) (a-floor(a))
#define sign(a) ((a>0) ? 1 : -1)
 
#pragma region Advisor
void WriteAdvice(unsigned char a);
 
void ComputeAdvice(int *C, int N, int K, int M) {
    vector<set<int>> used_times(N);
    for(int i = 0; i < N; i++) used_times[C[i]].insert(i);
    for(int i = 0; i < N; i++) used_times[i].insert(inf + 1);
 
    set<int> scaffold;
    set<pair<int, int>> scaffold_use_times;
    for(int i = 0; i < K; i++) {
        scaffold.insert(scaffold.end(), i);
        scaffold_use_times.insert({*used_times[i].begin(), i});
    }
 
    vector<set<int>> removed_times(N);
    for(int i = 0; i < N; i++) removed_times[i].insert(inf);
    for(int i = 0; i < N; i++) {
        int curr = C[i];
 
        if(setcontains(scaffold, curr)) continue;
 
        int worst = (--scaffold_use_times.end())->second;
        scaffold_use_times.erase(--scaffold_use_times.end());
        scaffold.erase(worst);
 
        scaffold.insert(curr);
        scaffold_use_times.insert({*used_times[curr].upper_bound(i), curr});
 
        removed_times[worst].insert(i);
    }
 
    vector<bool> bits(N + K);
    for(int i = 0; i < K; i++) {
        int next_use = *used_times[i].begin();
        int next_remove = *removed_times[i].begin();
 
        bits[i] = next_remove < next_use;
    }
 
    for(int i = 0; i < N; i++) {
        int next_use = *used_times[C[i]].upper_bound(i);
        int next_remove = *removed_times[C[i]].upper_bound(i);
 
        bits[K + i] = next_remove < next_use;
    }
 
    for(bool b : bits) WriteAdvice(b);
}
#pragma endregion
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <limits.h>
#include <math.h>
#include <chrono>
#include <queue>
#include <stack>
#include <algorithm>
 
using namespace std;
 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
 
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define p2 pair<ll, ll>
#define p3 tuple<ll,ll,ll>
#define p4 vi
#define ip3 tuple<int,int,int>
#define ip4 tuple<int,int,int,int>
#define vp2 vector<p2>
#define vp3 vector<p3>
#define inf 2e9
#define linf 1e17
 
#define read(a) cin >> a
#define write(a) cout << (a) << "\n"
#define dread(type, a) type a; cin >> a
#define dread2(type, a, b) dread(type, a); dread(type, b)
#define dread3(type, a, b, c) dread2(type, a, b); dread(type, c)
#define dread4(type, a, b, c, d) dread3(type, a, b, c); dread(type, d)
#define dread5(type, a, b, c, d, e) dread4(type, a, b, c, d); dread(type, e)
#ifdef _DEBUG
#define deb __debugbreak();
#else
#define deb ;
#endif
 
#define rep(i, high) for (ll i = 0; i < high; i++)
#define repp(i, low, high) for (ll i = low; i < high; i++)
#define repe(i, container) for (auto& i : container)
#define per(i, high) for (ll i = high; i >= 0; i--)
 
#define readpush(type,vect) type temp; read(temp); vect.push_back(temp);
#define readvector(type, name, size) vector<type> name(size); rep(i,size) {dread(type,temp); name[i]=temp;}
#define readinsert(type,a) {type temp; read(temp); a.insert(temp);}
#define all(a) begin(a),end(a)
#define setcontains(set, x) (set.find(x) != set.end())
#define stringcontains(str, x) (str.find(x) != string::npos)
#define within(a, b, c, d) (a >= 0 && a < b && c >= 0 && c < d)
 
#define ceildiv(x,y) ((x + y - 1) / y)
#define fract(a) (a-floor(a))
#define sign(a) ((a>0) ? 1 : -1)
 
#pragma region Assistant
void PutBack(int T);
int GetRequest();
 
void Assist(unsigned char *A, int N, int K, int R) {
    set<int> scaffold;
    for(int i = 0; i < K; i++) {
        scaffold.insert(scaffold.end(), i);
    }
 
    stack<int> removable;
    for(int i = 0; i < K; i++) if(A[i]) removable.push(i);
 
    int q_index = 0;
    for(int i = 0; i < N; i++) {
        int curr = GetRequest();
 
        if(!setcontains(scaffold, curr)) {
            int old_col = removable.top();
            removable.pop();
 
            PutBack(old_col);
 
            scaffold.erase(old_col);
            scaffold.insert(curr);
        }
 
        if(A[K + q_index]) removable.push(curr);
 
        q_index++;
    }
}
 
#pragma endregion

Compilation message

advisor.cpp:18: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   18 | #pragma GCC optimization ("O3")
      | 
advisor.cpp:19: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   19 | #pragma GCC optimization ("unroll-loops")
      | 
advisor.cpp:64: warning: ignoring '#pragma region Advisor' [-Wunknown-pragmas]
   64 | #pragma region Advisor
      | 
advisor.cpp:113: warning: ignoring '#pragma endregion ' [-Wunknown-pragmas]
  113 | #pragma endregion
      | 

assistant.cpp:18: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   18 | #pragma GCC optimization ("O3")
      | 
assistant.cpp:19: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   19 | #pragma GCC optimization ("unroll-loops")
      | 
assistant.cpp:64: warning: ignoring '#pragma region Assistant' [-Wunknown-pragmas]
   64 | #pragma region Assistant
      | 
assistant.cpp:97: warning: ignoring '#pragma endregion ' [-Wunknown-pragmas]
   97 | #pragma endregion
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 576 KB Output is correct
2 Incorrect 1 ms 512 KB Output isn't correct - not an optimal way
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 3692 KB Output isn't correct - not an optimal way
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 185 ms 27056 KB Output isn't correct - not an optimal way
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 1984 KB Output isn't correct - not an optimal way
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 210 ms 33080 KB Output isn't correct - not an optimal way
2 Incorrect 227 ms 33304 KB Output isn't correct - not an optimal way
3 Incorrect 244 ms 33612 KB Output isn't correct - not an optimal way
4 Incorrect 213 ms 33480 KB Output isn't correct - not an optimal way
5 Incorrect 213 ms 33572 KB Output isn't correct - not an optimal way
6 Incorrect 269 ms 33456 KB Output isn't correct - not an optimal way
7 Incorrect 213 ms 33584 KB Output isn't correct - not an optimal way
8 Incorrect 256 ms 33564 KB Output isn't correct - not an optimal way
9 Incorrect 270 ms 33532 KB Output isn't correct - not an optimal way
10 Correct 256 ms 34240 KB Output is correct - 125000 bits used