답안 #208683

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
208683 2020-03-12T01:58:48 Z E869120 수열 (BOI14_sequence) C++14
100 / 100
939 ms 2808 KB
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <ctime>
using namespace std;
#pragma warning (disable: 4996)

int N, A[1 << 18];
bool used[10000009][10];
bool used3[1009][10];
bool used4[10009][10];

int shou[200009], amari[200009];

void init() {
	for (int i = 0; i < 200000; i++) {
		shou[i] = i / 1000;
		amari[i] = i % 1000;
	}
	for (int i = 0; i < 10000; i++) {
		int cx = i;
		while (cx >= 1) {
			used[i][cx % 10] = true;
			cx /= 10;
		}
	}
	for (int i = 0; i < 1000; i++) {
		int cx = i;
		for (int j = 0; j < 3; j++) {
			used3[i][cx % 10] = true;
			cx /= 10;
		}
	}
	for (int i = 0; i < 10000; i++) {
		int cx = i;
		for (int j = 0; j < 4; j++) {
			used4[i][cx % 10] = true;
			cx /= 10;
		}
	}
}

bool check(int pos) {
	for (int i = 0; i < N; i++) {
		if (used[pos][A[i]] == false) return false;
		pos++;
	}
	return true;
}

int cnt[109][10];

void fixes(string &V, bool flag) {
	if (V == "") {
		if (flag == true) V = "1";
		else V = "0";
	}
	else if (V[0] == '0') {
		if (V.size() == 1) V = "10";
		else swap(V[0], V[1]);
	}
}

long long solve(int dig) {
	for (int i = 0; i < 101; i++) {
		for (int j = 0; j < 10; j++) cnt[i][j] = 0;
	}

	int maxt = 0, ret = 0;
	for (int i = 0; i < N; i++) {
		if (used3[amari[dig + i]][A[i]] == false) cnt[shou[dig + i]][A[i]] = 1;
	}
	maxt = (dig + N - 1) / 1000;

	vector<int> J[10];
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j <= maxt; j++) { if (cnt[j][i] == 1) J[i].push_back(j); }
	}

	// ケース 1: 下 3 桁が XYZ の場合
	long long m1 = (1LL << 60);
	for (int i = 0; i < 900; i++) {
		int v[10] = { 0,0,0,0,0,0,0,0,0,0 }; bool flag = false;
		for (int k = 0; k < 10; k++) {
			for (int j : J[k]) { if (used3[i + j][k] == false) { v[k] = 1; break; } }
		}
		for (int j : J[0]) { if (used[i + j][0] == false) { flag = true; break; } }

		long long val = 0, maxt = -1, r = 1;
		for (int j = 9; j >= 0; j--) {
			if (v[j] == 1) { val += r * j; if (j != 0) maxt = j; r *= 10; }
		}
		if (r == 1) {
			if (flag == true) val = 1;
		}
		else if (val < (r / 10LL)) {
			if (maxt == -1) val = 10;
			else val += 9LL * maxt * (r / 100LL);
		}
		long long eval = 1000000LL * val + 1000LL * i + dig;
		m1 = min(m1, eval);
	}

	// ケース 2: 下 4 桁が X9YZ の場合
	// どうやら存在しないらしい

	return m1;
}

int main() {
	scanf("%d", &N); init();
	for (int i = 0; i < N; i++) scanf("%d", &A[i]);

	// ステップ 1. 1000 以下を全探索
	for (int i = 1; i <= 100; i++) {
		if (check(i) == true) {
			cout << i << endl;
			return 0;
		}
	}

	// ステップ 2. そうでない場合
	long long minx = (1LL << 60);
	for (int i = 0; i <= 999; i++) {
		minx = min(minx, solve(i));
	}
	cout << minx << endl;
	return 0;
}

Compilation message

sequence.cpp:7:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning (disable: 4996)
 
sequence.cpp: In function 'long long int solve(int)':
sequence.cpp:70:16: warning: unused variable 'ret' [-Wunused-variable]
  int maxt = 0, ret = 0;
                ^~~
sequence.cpp: In function 'int main()':
sequence.cpp:112:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N); init();
  ~~~~~^~~~~~~~~~
sequence.cpp:113:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 0; i < N; i++) scanf("%d", &A[i]);
                              ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2040 KB Output is correct
2 Correct 82 ms 2040 KB Output is correct
3 Correct 6 ms 2168 KB Output is correct
4 Correct 79 ms 2044 KB Output is correct
5 Correct 6 ms 2168 KB Output is correct
6 Correct 6 ms 2296 KB Output is correct
7 Correct 40 ms 2168 KB Output is correct
8 Correct 43 ms 2040 KB Output is correct
9 Correct 6 ms 2168 KB Output is correct
10 Correct 83 ms 2040 KB Output is correct
11 Correct 6 ms 2040 KB Output is correct
12 Correct 79 ms 2040 KB Output is correct
13 Correct 86 ms 2168 KB Output is correct
14 Correct 84 ms 2168 KB Output is correct
15 Correct 83 ms 2040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2168 KB Output is correct
2 Correct 83 ms 2040 KB Output is correct
3 Correct 6 ms 2040 KB Output is correct
4 Correct 80 ms 2040 KB Output is correct
5 Correct 6 ms 2040 KB Output is correct
6 Correct 6 ms 2040 KB Output is correct
7 Correct 43 ms 2040 KB Output is correct
8 Correct 40 ms 2040 KB Output is correct
9 Correct 44 ms 2040 KB Output is correct
10 Correct 6 ms 2040 KB Output is correct
11 Correct 62 ms 2040 KB Output is correct
12 Correct 91 ms 2168 KB Output is correct
13 Correct 6 ms 2040 KB Output is correct
14 Correct 79 ms 2040 KB Output is correct
15 Correct 81 ms 2040 KB Output is correct
16 Correct 83 ms 2044 KB Output is correct
17 Correct 87 ms 2168 KB Output is correct
18 Correct 77 ms 2040 KB Output is correct
19 Correct 84 ms 2040 KB Output is correct
20 Correct 83 ms 2040 KB Output is correct
21 Correct 83 ms 2040 KB Output is correct
22 Correct 96 ms 2168 KB Output is correct
23 Correct 82 ms 2144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2040 KB Output is correct
2 Correct 87 ms 2168 KB Output is correct
3 Correct 88 ms 2172 KB Output is correct
4 Correct 89 ms 2168 KB Output is correct
5 Correct 91 ms 2300 KB Output is correct
6 Correct 76 ms 2168 KB Output is correct
7 Correct 360 ms 2296 KB Output is correct
8 Correct 244 ms 2424 KB Output is correct
9 Correct 495 ms 2424 KB Output is correct
10 Correct 499 ms 2552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2040 KB Output is correct
2 Correct 84 ms 2148 KB Output is correct
3 Correct 6 ms 2040 KB Output is correct
4 Correct 79 ms 2040 KB Output is correct
5 Correct 477 ms 2428 KB Output is correct
6 Correct 6 ms 2040 KB Output is correct
7 Correct 6 ms 2168 KB Output is correct
8 Correct 42 ms 2168 KB Output is correct
9 Correct 40 ms 2168 KB Output is correct
10 Correct 46 ms 2168 KB Output is correct
11 Correct 502 ms 2424 KB Output is correct
12 Correct 470 ms 2428 KB Output is correct
13 Correct 6 ms 2040 KB Output is correct
14 Correct 64 ms 2040 KB Output is correct
15 Correct 84 ms 2296 KB Output is correct
16 Correct 6 ms 2040 KB Output is correct
17 Correct 81 ms 2168 KB Output is correct
18 Correct 90 ms 2144 KB Output is correct
19 Correct 84 ms 2148 KB Output is correct
20 Correct 82 ms 2040 KB Output is correct
21 Correct 79 ms 2040 KB Output is correct
22 Correct 84 ms 2296 KB Output is correct
23 Correct 93 ms 2168 KB Output is correct
24 Correct 82 ms 2168 KB Output is correct
25 Correct 82 ms 2040 KB Output is correct
26 Correct 85 ms 2168 KB Output is correct
27 Correct 89 ms 2168 KB Output is correct
28 Correct 103 ms 2168 KB Output is correct
29 Correct 89 ms 2188 KB Output is correct
30 Correct 89 ms 2168 KB Output is correct
31 Correct 78 ms 2168 KB Output is correct
32 Correct 356 ms 2296 KB Output is correct
33 Correct 237 ms 2296 KB Output is correct
34 Correct 498 ms 2552 KB Output is correct
35 Correct 496 ms 2552 KB Output is correct
36 Correct 705 ms 2424 KB Output is correct
37 Correct 905 ms 2756 KB Output is correct
38 Correct 584 ms 2556 KB Output is correct
39 Correct 939 ms 2552 KB Output is correct
40 Correct 937 ms 2808 KB Output is correct