Submission #949365

# Submission time Handle Problem Language Result Execution time Memory
949365 2024-03-19T07:15:54 Z vjudge1 Painting Walls (APIO20_paint) C++17
Compilation error
0 ms 0 KB
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>

#include "paint.h"
#define rnd(l, r) uniform_int_distribution<int>(l, r)(rng)

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 

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) {
	unordered_map <int,int> mp[M];
	vector <int> ind[K + 1];
	for(int i = 0; i < M; i++){
		for(auto x : B[i]){
			ind[x].push_back(i);
			mp[i][x] = 1;
		}
	}
	memset(t, 0x3f3f, sizeof(t));
	for(int i = 0; i + M - 1 < N; i++){
		for(auto j : ind[C[i]]){
			bool flag = 1;
			for(int l = 0; l < M; l++){
				if(!mp[(l + j) % M].count(C[i + l])){
					flag = 0;
					break;
				}
			}
			if(flag){
				if(i == 0)
					update(i + M - 1, 1);

				else{
					int x = get(i - 1, i);
					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/ccLGvDF7.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccIPm9T9.o:paint.cpp:(.text.startup+0x20): first defined here
collect2: error: ld returned 1 exit status