답안 #676242

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
676242 2022-12-29T22:24:41 Z Sam_a17 벽 칠하기 (APIO20_paint) C++17
0 / 100
4 ms 9684 KB
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
//#include "temp.cpp"
#include <cstdio>
using namespace std;
 
#ifndef ONLINE_JUDGE
#define dbg(x) cerr << #x <<" "; print(x); cerr << endl;
#else
#define dbg(x)
#endif
 
#define sz(x) (int)x.size()
#define len(x) (int)x.length()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define clr(x) (x).clear()
#define uniq(x) x.resize(unique(all(x)) - x.begin());
#define blt __builtin_popcount
 
#define pb push_back
#define popf pop_front
#define popb pop_back
#define ld long double
 
void print(long long t) {cerr << t;}
void print(int t) {cerr << t;}
void print(string t) {cerr << t;}
void print(char t) {cerr << t;}
void print(double t) {cerr << t;}
void print(long double t) {cerr << t;}
void print(unsigned long long t) {cerr << t;}
 
template <class T, class V> void print(pair <T, V> p);
template <class T> void print(vector <T> v);
template <class T> void print(set <T> v);
template <class T, class V> void print(map <T, V> v);
template <class T> void print(multiset <T> v);
template <class T, class V> void print(T v[],V n) {cerr << "["; for(int i = 0; i < n; i++) {print(v[i]); cerr << " "; } cerr << "]";}
template <class T, class V> void print(pair <T, V> p) {cerr << "{"; print(p.first); cerr << ","; print(p.second); cerr << "}";}
template <class T> void print(vector <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
template <class T> void print(set <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
template <class T> void print(multiset <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void print(map <T, V> v) {cerr << "[ "; for (auto i : v) {print(i); cerr << " ";} cerr << "]";}
template <class T> void print(deque <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define nl '\n'
 
// for random generations
// mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count());
mt19937 myrand(373);
 
// for grid problems
int dx[8] = {-1,0,1,0,1,-1,1,-1};
int dy[8] = {0,1,0,-1,1,1,-1,-1};
 
// lowest / (1 << 17) >= 1e5 / (1 << 18) >= 2e5 / (1 << 21) >= 1e6
void fastIO() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr); cout.tie(nullptr);
}
// file in/out
void setIO(string str = "") {
  fastIO();
 
  if(str == "input") {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  } else {
    // freopen("skis.in", "r", stdin);
    // freopen("skis.out", "w", stdout);
  }
}
// Indexed Set  
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int maxN = 4e5 + 15, LOG = 22;
vector<int> st[maxN];
bool start[maxN];
int lst[maxN], dp[2][maxN];
int nxt[maxN], up[maxN][LOG];

int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B) {
  for(int i = 0; i < M; i++) {
    for(int j = 0; j < A[i]; j++) {
      st[B[i][j]].push_back(i);
    }
  }

  for(int i = 0; i < N; i++) {
    C.push_back(C[i]);
  }

  for(auto i: st[C[0]]) {
    dp[0][i] = 1;
    lst[0] = 1;
  }

  for(int i = 1; i < 2 * N; i++) {
    for(auto j: st[C[i]]) {
      int last_index = (j - 1 + M) % M;
      dp[i & 1][j] = max(dp[i & 1][j], dp[!(i & 1)][last_index] + 1);
      dp[i & 1][j] = min(dp[i & 1][j], M);
      lst[i] = max(lst[i], dp[i & 1][j]);
    }
    for(auto j: st[C[i - 1]]) {
      dp[!(i & 1)][j] = 0;
    }
  }

  for(int i = 0; i < 2 * N; i++) {
    if(lst[i] == M) {
      start[i] = true;
    }
  }
  
  for(int i = 0; i < LOG; i++) up[maxN - 10][i] = maxN - 10;
  nxt[maxN - 10] = maxN - 10;

  vector<int> xd{maxN - 10};
  for(int i = 2 * N - 1; i >= 0; i--) {
    if(start[i]) {
      xd.push_back(i);
      up[i][0] = max(0, i - M);
    }

    nxt[i] = xd.back();

 
    if(!start[i]) {
      up[i][0] = up[nxt[i]][0];
    }
  }

  for(int i = 1; i < LOG; i++) {
    for(int j = 2 * N - 1; j >= 0; j--) {
      int curr = up[j][i - 1];
      curr = nxt[curr];
      up[j][i] = up[curr][i - 1];
    }
  }

  int answ = maxN;
  for(int i = 2 * N - 1; i >= N; i--) {
    if(!start[i]) continue;
    
    int ina = 0, inb = N + 5, aw = -1;
    int L = i - N + 1, mxo = 0;

    while(ina <= inb) {
      int mid = (ina + inb) / 2;
      int cr = i;
      for(int j = 0; j < LOG; j++) {
        if(mid & (1 << j)) {
          cr = up[cr][j];
        }
      }
      mxo = max(mxo, cr);

      if(cr <= L) {
        aw = mid;
        inb = mid - 1;
      } else {
        ina = mid + 1;
      }
    }
    assert(mxo != (maxN - 10));

    if(aw != -1) {
      answ = min(answ, aw);
    }
  }

  if(answ == maxN) answ = -1;
  return answ;
}

Compilation message

paint.cpp: In function 'void setIO(std::string)':
paint.cpp:69:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
paint.cpp:70:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |     freopen("output.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 9684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 9684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 9684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 9684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 9684 KB Output isn't correct
2 Halted 0 ms 0 KB -