답안 #949327

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
949327 2024-03-19T06:24:38 Z vjudge1 벽 칠하기 (APIO20_paint) C++17
컴파일 오류
0 ms 0 KB
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>

#include "paint.h"


using namespace std;

const int inf = 1e9, N1 = 1e5 + 10, MX = 1e5 + 1;

int t[N1 * 4];

void update(int pos, int x, int v = 1,int tl = 0, int tr = MX){
    if(tl == tr){
        t[v] = x;
    }else{
        int mid = (tl + tr) >> 1;
        if(pos <= mid)
			update(pos, x, v * 2, tl, mid);
        else
			update(pos, x, v * 2 + 1,mid + 1, tr);
        t[v] = min(t[v * 2], t[v * 2 + 1]);
    }
}
 
int get(int l, int r, int v = 1, int tl = 0, int tr = MX){
    if(tl > r || tr < l)
        return inf;
    if(tl >= l && tr <= r){
        return t[v];
    }
    int mid = (tl + tr) >> 1;
    return min(get(l, r, v * 2, tl, mid),get(l, r, v * 2 + 1, mid + 1, tr));
}


int minimumInstructions(
    int N, int M, int K, std::vector<int> C,
    std::vector<int> A, std::vector<std::vector<int>> B) {
	set <int> st[M];
	for(int i = 0; i < M; i++){
		for(auto x : B[i]){
			st[i].insert(x);
		}
	}
	memset(t, 0x3f3f, sizeof(t));
	for(int i = 0; i + M - 1 < N; i++){
		for(int j = 0; j < M; j++){
			bool flag = 1;
			for(int l = 0; l < M; l++){
				if(st[(l + j) % M].find(C[i + l]) == st[(l + j) % M].end()){
					flag = 0;
					break;
				}
			}
			if(flag){
				if(i == 0)
					update(i + M - 1, 1);

				else{
					int x = get(i - 1, i + M - 2);
					update(i + M - 1, x + 1);
				}
				//cout << i  + M - 1<<"-"<< get(0, 0) << endl;
				//break;
			}
		}
	}
	int ans = get(N - 1, N  - 1);
	if(ans == inf)
		return -1;
	return ans;
}



int main() {
  int N, M, K;
  assert(3 == scanf("%d %d %d", &N, &M, &K));
  
  std::vector<int> C(N);
  for (int i = 0; i < N; ++i) {
    assert(1 == scanf("%d", &C[i]));
  }

  std::vector<int> A(M);
  std::vector<std::vector<int>> B(M);
  for (int i = 0; i < M; ++i) {
    assert(1 == scanf("%d", &A[i]));
    B[i].resize(A[i]);
    for (int j = 0; j < A[i]; ++j) {
      assert(1 == scanf("%d", &B[i][j]));
    }
  }

  int minimum_instructions = minimumInstructions(N, M, K, C, A, B);
  printf("%d\n", minimum_instructions);
  
  return 0;
}


Compilation message

/usr/bin/ld: /tmp/ccuyCoAS.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccwwPoUP.o:paint.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status