Submission #2025

#TimeUsernameProblemLanguageResultExecution timeMemory
2025solve생일수 I (GA4_birthday1)C++98
59 / 100
2 ms2160 KiB
#include <iostream> #include <queue> using namespace std; int N, chk[100005], from[100005]; int nums[] = {3, 5, 8}; queue<int> q; void solve() { fill(chk, chk + 1 + 100000, 0); fill(from, from + 1 + 100000, -1); for(int i = 0;i<3;i++) { q.push(nums[i]); chk[nums[i]] = 1; from[nums[i]] = 0; } while(!q.empty()) { int n = q.front(); q.pop(); for(int i = 0;i<3;i++) { if(n + nums[i] > 100000) break; if(!chk[n + nums[i]]) { chk[n + nums[i]] = 1; from[n + nums[i]] = n; q.push(n + nums[i]); } } } } void print(int idx) { if(idx == 0) return; print(from[idx]); printf("%d",idx - from[idx]); } int main() { int T; solve(); scanf("%d",&T); while(T--) { scanf("%d",&N); if(from[N] == -1) { printf("%d\n", -1); } else { print(N); printf("\n"); } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...