답안 #399663

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
399663 2021-05-06T11:20:42 Z A_D 벽 칠하기 (APIO20_paint) C++14
컴파일 오류
0 ms 0 KB
//#include "paint.h"
#include <bits/stdc++.h>
#define pair<int,int>
using namespace std;
const int NN=1e5+100;
bool freq[NN];
vector<int> like[NN];
vector<int> c;
vector<int> a;
int n,m,k;
map<int,bool> mp[NN];
bool ok(int x,int y)
{
    for(int l=0;l<m;l++){
        if(mp[(x+l)%m][c[y+l]]==0){
            return 0;
        }
    }
    return 1;
}
int minimumInstructions(
    int N, int M, int K, std::vector<int> C,
    std::vector<int> A, std::vector<std::vector<int>> B)
    {
        a=A;
        c=C;
        n=N;
        m=M;
        k=K;
        int maxx=0;
//        cout<<5<<endl;
        for(int i=0;i<m;i++){
            for(auto x:B[i]){
                mp[i][x]=1;
                like[x].push_back(i);
            }
        }
        for(int i=0;i<k;i++){
            maxx=max(maxx,like[i].size());
        }
  //      cout<<5<<endl;
        int idx=-1;
        int cnt=0;
        if(maxx<=1){
            
            for(int i=0;i<n;i++){
                int v=c[i];
                if(like[v].empty())return -1;
                if(like[v][0]==idx){
                    cnt++;
                }
                else{
                    cnt=1;
                    idx=like[v][0];
                }
                if(cnt>=m){
                    freq[i-m+1]=cnt;
                }
                idx++;
                idx%=m;
            }
        }
        else{
            for(int j=0;j<=n-m;j+=m){
                for(auto i:like[c[j]]){
                    if(ok(i,j)){
                        freq[j]=1;
                        break;
                    }
                }
            }
        }
        int mx=0;
        int ans=0;
        int i=0;
    //    cout<<5<<endl;
        while(mx<n){
            int v=mx;
      //      cout<<mx<<endl;
            ans++;
            while(i<=mx){
                if(freq[i]){
                    v=max(v,i+m);
                }
                i++;
            }
            if(v==mx)break;
            mx=v;
        }
        if(mx<n)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;
}
*/
/*
8 3 5
3 3 1 3 4 4 2 2
3 0 1 2
2 2 3
2 3 4
*/

Compilation message

paint.cpp:3:9: warning: ISO C++11 requires whitespace after the macro name
    3 | #define pair<int,int>
      |         ^~~~
paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:39:41: error: no matching function for call to 'max(int&, std::vector<int>::size_type)'
   39 |             maxx=max(maxx,like[i].size());
      |                                         ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from paint.cpp:2:
/usr/include/c++/9/bits/stl_algobase.h:222:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  222 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:222:5: note:   template argument deduction/substitution failed:
paint.cpp:39:41: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::vector<int>::size_type' {aka 'long unsigned int'})
   39 |             maxx=max(maxx,like[i].size());
      |                                         ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from paint.cpp:2:
/usr/include/c++/9/bits/stl_algobase.h:268:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  268 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:268:5: note:   template argument deduction/substitution failed:
paint.cpp:39:41: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::vector<int>::size_type' {aka 'long unsigned int'})
   39 |             maxx=max(maxx,like[i].size());
      |                                         ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from paint.cpp:2:
/usr/include/c++/9/bits/stl_algo.h:3456:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3456 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
paint.cpp:39:41: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   39 |             maxx=max(maxx,like[i].size());
      |                                         ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from paint.cpp:2:
/usr/include/c++/9/bits/stl_algo.h:3462:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3462 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
paint.cpp:39:41: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   39 |             maxx=max(maxx,like[i].size());
      |                                         ^