답안 #1022383

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1022383 2024-07-13T12:34:17 Z gvancak Hidden Sequence (info1cup18_hidden) C++11
100 / 100
4 ms 436 KB
#include<bits/stdc++.h>
#include "grader.h"
#define pb push_back
using namespace std;
 
vector < int > findSequence (int N)
{
    vector < int > ans,v;
    int cnt1=0,cnt0=0;
    bool ok;
    int c0,c1,x;
    for (int i=1; i<=N/2+1; i++) v.push_back(0);
    ok=isSubsequence (v);
    if (ok==1){
    	x=N/2+1;
    	cnt1=0;
    	while (1){
    		if (x==0) break; v.clear();
    		for (int i=1; i<=x; i++) v.push_back(1);
    		ok=isSubsequence (v);
    		if (ok==1){
    			cnt1=x; break;
			}
			x--;
		}
		if (cnt1==0){
			for (int i=1; i<=N; i++) ans.pb(0); return ans;
		}
		if (cnt1==N){
			for (int i=1; i<=N; i++) ans.pb(1); return ans;
		}
		cnt0=N-cnt1;
		//1<0
		 c0=0; c1=1;
		while (c1<=cnt1){
			v.clear();
			if (c1+cnt0-c0<=N/2+1){
				for (int i=1; i<=c1; i++) v.push_back(1);
				for (int i=1; i<=cnt0-c0; i++) v.push_back(0);
				ok=isSubsequence (v);
				if (ok==0){
					ans.push_back(0); c0++;
				}
				else{
					ans.push_back(1); c1++;
				}
			}
			else{
				// c1+1+cnt0-ind+1<=N/2+1
				for (int i=1; i<=min(c0+1,cnt0); i++) v.push_back(0);
				for (int i=1; i<=cnt1-c1+1; i++) v.push_back(1);
				ok=isSubsequence (v);
				if (ok==0){
					ans.push_back(1); c1++;
				}
				else{
					ans.push_back(0); c0++;
				}
			}
		}
		x=ans.size();
		for (int i=x+1; i<=N; i++) ans.push_back(0);
		
	}
	else{
		x=N/2+1;
    	cnt0=0;
    	while (1){
    		if (x==0) break; v.clear();
    		for (int i=1; i<=x; i++) v.push_back(0);
    		ok=isSubsequence (v);
    		if (ok==1){
    			cnt0=x; break;
			}	
			x--;	
		}
		if (cnt0==0){
			for (int i=1; i<=N; i++) ans.pb(1); return ans;
		}
		if (cnt0==N){
			for (int i=1; i<=N; i++) ans.pb(0); return ans;
		}
		cnt1=N-cnt0;
		//0<1
	 c0=1; c1=0;
		while (c0<=cnt0){
			v.clear();
			if (c0+cnt1-c1<=N/2+1){
				for (int i=1; i<=c0; i++) v.push_back(0);
				for (int i=1; i<=cnt1-c1; i++) v.push_back(1);
				ok=isSubsequence (v);
				if (ok==1){
					ans.push_back(0); c0++;
				}
				else{
					ans.push_back(1); c1++;
				}
			}
			else{
				// c1+1+cnt0-ind+1<=N/2+1
				for (int i=1; i<=min(c1+1,cnt1); i++) v.push_back(1);
				for (int i=1; i<=cnt0-c0+1; i++) v.push_back(0);
				ok=isSubsequence (v);
				if (ok==1){
					ans.push_back(1); c1++;
				}
				else{
					ans.push_back(0); c0++;
				}
			}
		}
		x=ans.size();
		for (int i=x+1; i<=N; i++) ans.push_back(1);
		
	}
    return ans;
}

Compilation message

hidden.cpp: In function 'std::vector<int> findSequence(int)':
hidden.cpp:18:7: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   18 |       if (x==0) break; v.clear();
      |       ^~
hidden.cpp:18:24: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   18 |       if (x==0) break; v.clear();
      |                        ^
hidden.cpp:27:4: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   27 |    for (int i=1; i<=N; i++) ans.pb(0); return ans;
      |    ^~~
hidden.cpp:27:40: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   27 |    for (int i=1; i<=N; i++) ans.pb(0); return ans;
      |                                        ^~~~~~
hidden.cpp:30:4: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   30 |    for (int i=1; i<=N; i++) ans.pb(1); return ans;
      |    ^~~
hidden.cpp:30:40: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   30 |    for (int i=1; i<=N; i++) ans.pb(1); return ans;
      |                                        ^~~~~~
hidden.cpp:69:7: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   69 |       if (x==0) break; v.clear();
      |       ^~
hidden.cpp:69:24: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   69 |       if (x==0) break; v.clear();
      |                        ^
hidden.cpp:78:4: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   78 |    for (int i=1; i<=N; i++) ans.pb(1); return ans;
      |    ^~~
hidden.cpp:78:40: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   78 |    for (int i=1; i<=N; i++) ans.pb(1); return ans;
      |                                        ^~~~~~
hidden.cpp:81:4: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   81 |    for (int i=1; i<=N; i++) ans.pb(0); return ans;
      |    ^~~
hidden.cpp:81:40: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   81 |    for (int i=1; i<=N; i++) ans.pb(0); return ans;
      |                                        ^~~~~~
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++)
      |                   ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct: Maximum length of a query = 5
2 Correct 0 ms 344 KB Output is correct: Maximum length of a query = 6
3 Correct 1 ms 344 KB Output is correct: Maximum length of a query = 5
4 Correct 1 ms 344 KB Output is correct: Maximum length of a query = 5
5 Correct 0 ms 344 KB Output is correct: Maximum length of a query = 4
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct: Maximum length of a query = 83
2 Correct 3 ms 436 KB Output is correct: Maximum length of a query = 90
3 Correct 3 ms 344 KB Output is correct: Maximum length of a query = 96
4 Correct 2 ms 344 KB Output is correct: Maximum length of a query = 77
5 Correct 2 ms 344 KB Output is correct: Maximum length of a query = 95
6 Correct 2 ms 344 KB Output is correct: Maximum length of a query = 87
7 Correct 2 ms 344 KB Output is correct: Maximum length of a query = 97
8 Correct 3 ms 344 KB Output is correct: Maximum length of a query = 83
9 Correct 2 ms 344 KB Output is correct: Maximum length of a query = 101
10 Correct 2 ms 344 KB Output is correct: Maximum length of a query = 100
11 Correct 2 ms 344 KB Output is correct: Maximum length of a query = 96
12 Correct 2 ms 344 KB Output is correct: Maximum length of a query = 100
13 Correct 4 ms 344 KB Output is correct: Maximum length of a query = 101