Submission #45708

# Submission time Handle Problem Language Result Execution time Memory
45708 2018-04-16T04:21:38 Z mirbek01 Jakarta Skyscrapers (APIO15_skyscraper) C++17
0 / 100
2 ms 748 KB
# include <bits/stdc++.h>

using namespace std;

const int N = 30005;

int n, m, b[N], p[N], a[N], c[N], ans = 1e9;

int main(){
      cin >> n >> m;

      for(int i = 1; i <= m; i ++){
            cin >> b[i] >> p[i];
      }

      if(n > 10 || m > 3) return 0;
      for(int i = b[1]; i + p[1] < n; i += p[1]){
            a[i + p[1]] = a[i] + 1;
      }
      for(int i = b[1]; i - p[1] >= 0; i -= p[1]){
            a[i - p[1]] = a[i] + 1;
      }
      if(m > 2){

      for(int i = b[3]; i + p[3] < n; i += p[3]){
            c[i + p[3]] = c[i] + 1;
      }
      for(int i = b[3]; i - p[3] >= 0; i -= p[3]){
            c[i - p[3]] = c[i] + 1;
      }
      }

      if(a[b[2]])
            ans = a[b[2]];
      if(m > 2)
      if(c[b[2]] && a[b[3]]){
            ans = min(ans, a[b[3]] + c[b[2]]);
      }

      if(ans == 1e9)
            cout << -1 << endl;
      else
            cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Incorrect 2 ms 356 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 408 KB Output is correct
2 Incorrect 2 ms 456 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Incorrect 2 ms 544 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 620 KB Output is correct
2 Incorrect 2 ms 748 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 748 KB Output is correct
2 Incorrect 2 ms 748 KB Output isn't correct
3 Halted 0 ms 0 KB -