답안 #923398

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
923398 2024-02-07T07:23:25 Z vjudge1 Hidden Sequence (info1cup18_hidden) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include "grader.h"

#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")

using namespace std;

#define pb push_back


vector<int> findSequence(int n){
  int L=(n/2)+1;
  int c1=-1,c0=-1;
  for(int i=1;i<=L;i++){
    vector<int> v;
    for(int j=1;j<=i;j++)v.pb(1);
    if(!isSubsequence(v)){
      c1=i-1;
      c0=n-c1;
      break;
    }
  }
  for(int i=1;i<=L;i++){
    vector<int> v;
    for(int j=1;j<=i;j++)v.pb(0);
    if(!isSubsequence(v)){
      c0=i-1;
      c1=n-c0;
      break;
    }
  }
  if(c1<=0){
    for(int i=1;i<=n;i++)ans.pb(0);
    return ans;
  }
  if(c0<=0){
    for(int i=1;i<=n;i++)ans.pb(1);
    return ans;
  }
  vector<int> ans;
  int cnt0=0,cnt1=0;
  for(int i=1;i<=n;i++){
    if(!c1){
      ans.pb(0);
      continue;
    }
    if(!c0){
      ans.pb(1);
      continue;
    }
    vector<int> v;
    if(cnt0<=cnt1){
      for(int i=1;i<=cnt0;i++)v.pb(0);
    }
    else{
      for(int i=1;i<=cnt1;i++)v.pb(1);
    }
    if(!ans.empty()){
      if(v.empty())v.pb(ans.back());
      else if(v.back()!=ans.back())ans.pb(ans.back());
    }
    if(c0<=c1){
      v.pb(1);
      for(int i=1;i<=c0;i++)v.pb(0);
      if(!isSubsequence(v)){
        ans.pb(0);
        c0--;
        cnt0++;
      }
      else{
        ans.pb(1);
        c1--;
        cnt1++;
      }
    }
    else{
      ans.pb(0);
      for(int i=1;i<=c1;i++)ans.pb(1);
      if(isSubsequence(v)){
        ans.pb(0);
        c0--;
        cnt0++;
      }
      else{
        ans.pb(1);
        c1--;
        cnt1++;
      }
    }
  }
  assert(c0+c1==0);
  return ans;
}

Compilation message

hidden.cpp: In function 'std::vector<int> findSequence(int)':
hidden.cpp:34:26: error: 'ans' was not declared in this scope; did you mean 'abs'?
   34 |     for(int i=1;i<=n;i++)ans.pb(0);
      |                          ^~~
      |                          abs
hidden.cpp:35:12: error: 'ans' was not declared in this scope; did you mean 'abs'?
   35 |     return ans;
      |            ^~~
      |            abs
hidden.cpp:38:26: error: 'ans' was not declared in this scope; did you mean 'abs'?
   38 |     for(int i=1;i<=n;i++)ans.pb(1);
      |                          ^~~
      |                          abs
hidden.cpp:39:12: error: 'ans' was not declared in this scope; did you mean 'abs'?
   39 |     return ans;
      |            ^~~
      |            abs
grader.cpp: In function 'int main()':
grader.cpp:28:26: warning: format '%d' expects argument of type 'int', but argument 3 has type 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
   28 |     fprintf (fifo_out, "%d\n", ans.size ());
      |                         ~^     ~~~~~~~~~~~
      |                          |              |
      |                          int            std::vector<int>::size_type {aka long unsigned int}
      |                         %ld
grader.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for (int i=0; i<ans.size () && i < N; i++)
      |                   ~^~~~~~~~~~~~