Submission #2025

# Submission time Handle Problem Language Result Execution time Memory
2025 2013-07-19T19:53:40 Z solve 생일수 I (GA4_birthday1) C++
59 / 100
2 ms 2160 KB
#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 time Memory Grader output
1 Correct 1 ms 2160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2160 KB Output is correct
2 Correct 1 ms 2160 KB Output is correct
3 Correct 1 ms 2160 KB Output is correct
4 Correct 0 ms 2160 KB Output is correct
5 Correct 1 ms 2160 KB Output is correct
6 Correct 2 ms 2160 KB Output is correct
7 Correct 1 ms 2160 KB Output is correct
8 Correct 0 ms 2160 KB Output is correct
9 Correct 0 ms 2160 KB Output is correct
10 Correct 1 ms 2160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 2156 KB SIGSEGV Segmentation fault
2 Halted 0 ms 0 KB -