답안 #1000483

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1000483 2024-06-17T15:03:49 Z LOLOLO 수열 (BOI14_sequence) C++14
0 / 100
777 ms 262144 KB
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
typedef long long ll;
using namespace std;
 
ll solve(const vector<int>& v, bool not9)
{
	if (v.size() == 1)
	{
		ll ans = 0;
		for (int i = 1; i <= 9; i++) if (v[0] & (1 << i))
		{
			ans = ans * 10 + i;
			if (ans == i && (v[0] & 1)) ans *= 10;
		}
		if (!ans && (v[0] & 1)) ans = 10;
		return ans;
	}
	else
	{
		ll ans = 1e16;
		for (int last = 0; last <= 9; last++)
		{
			vector<int> v2;
			int mask = 0;
			bool zero = false;
			for (int i = 0, j = last; i < v.size(); i++, j = (j + 1) % 10)
			{
				int my = v[i];
				if (my & (1 << j)) my ^= (1 << j);
				mask |= my;
				if (!j && (v[i] & 1)) zero = true;
				if (j == 9 || i + 1 == v.size())
				{
					v2.push_back(mask);
					mask = 0;
				}
			}
			ll num = solve(v2, (v.size() == 2 && last == 9)) * 10 + last;
			if (!num && zero) num = 10; // potrebujeme mat nieco na zaciatku, aby nam neodisla ta 0
			ans = min(ans, num);
		}
		return ans;
	}
}
 
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int k;
	cin >> k;
	vector<int> v(k);
	for (int i = 0; i < k; i++) cin >> v[i], v[i] = (1 << v[i]);
	cout << solve(v, false) << "\n";
	return 0;
}

Compilation message

sequence.cpp: In function 'll solve(const std::vector<int>&, bool)':
sequence.cpp:29:32: 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, j = last; i < v.size(); i++, j = (j + 1) % 10)
      |                              ~~^~~~~~~~~~
sequence.cpp:35:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     if (j == 9 || i + 1 == v.size())
      |                   ~~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 777 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 645 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Runtime error 629 ms 262144 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 652 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -