# 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;
}
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(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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Execution timed out |
1081 ms |
376 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
420 KB |
Output is correct |
2 |
Execution timed out |
1072 ms |
544 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
544 KB |
Output is correct |
2 |
Execution timed out |
1090 ms |
704 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
704 KB |
Output is correct |
2 |
Execution timed out |
1068 ms |
704 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
704 KB |
Output is correct |
2 |
Execution timed out |
1087 ms |
704 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |