Submission #2024

# Submission time Handle Problem Language Result Execution time Memory
2024 2013-07-19T19:46:35 Z solve 생일수 I (GA4_birthday1) C++
59 / 100
1 ms 2160 KB
#include <iostream>
#include <queue>

using namespace std;

int N, chk[100005], from[100005];
int nums[] = {3, 5, 8};

void solve() {
  fill(chk, chk + 1 + 100000, 0);
  fill(from, from + 1 + 100000, -1);
  queue<int> q;
  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]);
      }
    }
  }
}

int main() {
  int T;
  solve();
  scanf("%d",&T);
  while(T--) {
    scanf("%d",&N);
    if(from[N] == -1) {
      printf("%d\n", -1);
    }
    else {
      vector<int> res;
      int idx = N;
      while(idx != 0) {
        res.push_back(idx - from[idx]);
        idx = from[idx];
      }
      for(int i = res.size() - 1;i>=0;i--)
        printf("%d",res[i]);
      printf("\n");
    }
  }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 1 ms 2160 KB Output is correct
5 Correct 1 ms 2160 KB Output is correct
6 Correct 1 ms 2160 KB Output is correct
7 Correct 1 ms 2160 KB Output is correct
8 Correct 1 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 0 ms 2156 KB SIGSEGV Segmentation fault
2 Halted 0 ms 0 KB -