# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
786123 | christinelynn | Jakarta Skyscrapers (APIO15_skyscraper) | C++17 | 1 ms | 276 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define sec second
#define pb push_back
#define pqueue priority_queue
#define int long long
#define pii pair<int,int>
#define supercepat ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
using namespace std;
int tc,ans=0,n,m;
int b[30005],p[30005];
main(){
supercepat;
cin>>n>>m;
for(int i=0;i<m;i++){
cin>>b[i]>>p[i];
}
if(m==2){
if(abs(b[1]-b[0])%p[0]==0) cout<<abs(b[1]-b[0])/p[0];
else cout<<-1<<endl;
}
else if(m==3){
ans=LLONG_MAX;
//langsung
bool ok=0;
if(abs(b[1]-b[0])%p[0]==0){
ok=1;
ans=min(ans,abs(b[1]-b[0])/p[0]);
}
//ke 2 dulu
if(abs(b[2]-b[0])%p[0]==0&&abs(b[2]-b[1])%p[2]==0){
ok=1;
ans=min(ans,(abs(b[2]-b[0])/p[0])+(abs(b[2]-b[1])/p[2]));
}
if(ok) cout<<ans<<endl;
else cout<<-1<<endl;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |