답안 #317187

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
317187 2020-10-29T05:07:34 Z 8e7 Hidden Sequence (info1cup18_hidden) C++14
20 / 100
6 ms 512 KB
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include "grader.h"
#define ll long long
#define pii pair<int, int>
#define maxn 200005
using namespace std;
bool poss[1<<10];
bool adj[1<<10][1<<10];

bool Sub (int v, int u, int n, int vs) {
    int i = 0;
    for (int x = 0;x < vs;x++) {
        while (i < n && ((v & (1<<x)) ? 1 : 0) != ((u & (1<<i)) ? 1 : 0)) i ++;
        if (i == n) return 0;
        i ++;
    }
    return 1;
}
inline int hbit(int a) {
	int ret = 0;
	while (a) {
		ret++;
		a >>= 1;
	}
	return max(ret, 1);
}
vector < int > findSequence (int n) {
	if (n <= 10) {
		int len = n / 2 + 1;
		for (int i = 0;i < (1<<len);i++) {
			int h = hbit(i);
			//cout << i << ' ' << h << endl;
			for (int j = 0;j < (1<<n);j++) {
				if (Sub(i, j, n, len)) {
					//cout << i << " " << j << endl;
					adj[i][j] = 1;
				}
			}
		}
		for (int i = 0;i < (1<<len);i++) {
			vector<int> v;
			for (int j = 0;j < len;j++) {
				if (i & (1<<j)) {
					v.push_back(1);
				} else {
					v.push_back(0);
				}
			}
			if (isSubsequence(v)) {
				for (int j = 0;j < (1<<n);j++) {
					if (!adj[i][j]) {
						poss[j] = true;
						//cout << i << " " << j << endl;
					}
				}
			} else {
				for (int j = 0;j < (1<<n);j++) {
					if (adj[i][j]) {
						poss[j] = true;
						//cout << i << " " << j << endl;
					}
				}
			}
		}
		for (int i = 0;i < (1<<n);i++) {
			if (!poss[i]) {
				vector<int> v;
				for (int j = 0;j < n;j++) {
					if (i & (1<<j)) {
						v.push_back(1);
					} else {
						v.push_back(0);
					}
					//cout << v[v.size() - 1];
				}
				return v;
			}
		}
		return vector<int>();
	} else {
		int c0 = 0, c1 = 0;
		for (int i = 1;i <= n;i++) {
			vector<int> v;
			for (int j = 0;j < i;j++) v.push_back(0);
			if (isSubsequence(v)) {
				c0 = i;
			} else {
				break;
			}
		}
		c1 = n -c0;
		vector<int> ans;
		for (int i = 1;i <= n;i++) {
			vector<int> v = ans;
			v.push_back(0);
			for (int j = 0;j < min(int(n - v.size()), c1);j++) v.push_back(1);
			//for (int x = 0;x < v.size();x++) {
				//cout << v[x];
			//}
			//cout << endl;
			if (isSubsequence(v)) {
				ans.push_back(0);
			} else {
				ans.push_back(1);
				c1--;
			}
		}
		return ans;
	}
}

Compilation message

hidden.cpp: In function 'std::vector<int> findSequence(int)':
hidden.cpp:34:8: warning: unused variable 'h' [-Wunused-variable]
   34 |    int h = hbit(i);
      |        ^
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 412 KB Output is correct: Maximum length of a query = 5
2 Correct 5 ms 512 KB Output is correct: Maximum length of a query = 6
3 Correct 1 ms 384 KB Output is correct: Maximum length of a query = 5
4 Correct 2 ms 384 KB Output is correct: Maximum length of a query = 5
5 Correct 1 ms 384 KB Output is correct: Maximum length of a query = 4
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 384 KB Output is not correct: The returned sequence does not match the hidden one
2 Halted 0 ms 0 KB -