Submission #1063898

# Submission time Handle Problem Language Result Execution time Memory
1063898 2024-08-18T05:48:08 Z rlx0090 생일수 I (GA4_birthday1) C++14
100 / 100
230 ms 30804 KB
#include <iostream>
#include <vector>
#include <fstream>
#include <cstring>
#include <string>
#include <queue>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cfloat>
#include <random>

using namespace std;

struct birthdayNumber {
	int len, three, five, eight;
	const bool operator<(const birthdayNumber& rhs) const {
		if(len != rhs.len) return len < rhs.len;
		if(three != rhs.three) return three < rhs.three;
		if(five != rhs.five) return five < rhs.five;
		return eight < rhs.eight;
	}
	const bool operator==(const birthdayNumber& rhs) const {
		return len == rhs.len && three == rhs.three && five == rhs.five && eight == rhs.eight;
	}
};
vector<birthdayNumber> cache(1e6 + 5, {987654321, 987654321, 987654321, 987654321});
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cache[3].len = 1;
	cache[3].three = 1;
	cache[5].len = 1;
	cache[5].five = 1;
	cache[6].len = 2;
	cache[6].three = 2;
	cache[8].len = 1;
	cache[8].eight = 1;

	for(int i = 9; i <= 1000000; ++i) {
		birthdayNumber a, b, c;
		a = cache[i - 3];
		b = cache[i - 5];
		c = cache[i - 8];
		birthdayNumber d = min({a, b, c});

		if(d == a) {
			cache[i] = a;
			cache[i].three++;
		} else if(d == b) {
			cache[i] = b;
			cache[i].five++;
		} else {
			cache[i] = c;
			cache[i].eight++;
		}
		cache[i].len++;
	}

	int t;
	cin >> t;
	// int rr = t;
	int e = 0;
	vector<string> a(t, "");
	while(t--) {
		int n;
		cin >> n;
		if(cache[n].len == 987654321){a[e++] = "-1"; cout << -1 << '\n';}
		else {
			if(cache[n].three >= 987654321) cache[n].three -= 987654321;
			if(cache[n].five >= 987654321) cache[n].five -= 987654321;
			if(cache[n].eight >= 987654321) cache[n].eight -= 987654321;
			// cout << cache[n].three << " " << cache[n].five << " " << cache[n].eight << endl;
			
			for(int i = 0; i < cache[n].three; ++i)
				a[e] += '3';
			for(int i = 0; i < cache[n].five; ++i)
				a[e] += '5';
			for(int i = 0; i < cache[n].eight; ++i)
				a[e] += '8';
			e++;
			// cout << '\n';
			
			for(int i = 0; i < cache[n].three; ++i)
				cout << 3;
			for(int i = 0; i < cache[n].five; ++i)
				cout << 5;
			for(int i = 0; i < cache[n].eight; ++i)
				cout << 8;
			cout << '\n';
		}
	}
	// for(int i = 0; i < rr; ++i) {
	// 	string s;
	// 	cin >> s;
	// 	if(s != a[i]) {
	// 		cout << "ans: " << s << " handed : " << a[i] << endl;
	// 	}
	// }
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 15960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 15960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 15964 KB Output is correct
2 Correct 14 ms 15964 KB Output is correct
3 Correct 13 ms 16124 KB Output is correct
4 Correct 15 ms 15964 KB Output is correct
5 Correct 13 ms 15964 KB Output is correct
6 Correct 14 ms 15964 KB Output is correct
7 Correct 15 ms 15964 KB Output is correct
8 Correct 13 ms 15964 KB Output is correct
9 Correct 13 ms 15964 KB Output is correct
10 Correct 13 ms 15988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 221 ms 30032 KB Output is correct
2 Correct 201 ms 28860 KB Output is correct
3 Correct 230 ms 30220 KB Output is correct
4 Correct 220 ms 30104 KB Output is correct
5 Correct 217 ms 29132 KB Output is correct
6 Correct 223 ms 30804 KB Output is correct
7 Correct 203 ms 28440 KB Output is correct
8 Correct 216 ms 29664 KB Output is correct
9 Correct 223 ms 30376 KB Output is correct
10 Correct 209 ms 29012 KB Output is correct
11 Correct 205 ms 29012 KB Output is correct
12 Correct 214 ms 28592 KB Output is correct
13 Correct 220 ms 29676 KB Output is correct
14 Correct 213 ms 29528 KB Output is correct
15 Correct 194 ms 28540 KB Output is correct
16 Correct 210 ms 29268 KB Output is correct
17 Correct 222 ms 29908 KB Output is correct
18 Correct 196 ms 28312 KB Output is correct
19 Correct 218 ms 29156 KB Output is correct
20 Correct 189 ms 28144 KB Output is correct
21 Correct 215 ms 29728 KB Output is correct
22 Correct 215 ms 29608 KB Output is correct
23 Correct 217 ms 29880 KB Output is correct
24 Correct 224 ms 29780 KB Output is correct
25 Correct 213 ms 29696 KB Output is correct