Submission #923921

# Submission time Handle Problem Language Result Execution time Memory
923921 2024-02-08T06:38:35 Z ezzzay Jakarta Skyscrapers (APIO15_skyscraper) C++14
0 / 100
0 ms 348 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define ff first
#define ss second
#define pb push_back
#define inf 1e17
const int N=15;
int arr[N][N];
int cur[N],pw[N];
signed main(){
    int n,m;
    cin>>n>>m;
    vector<int>v;
    for(int i=0;i<m;i++){
        cin>>cur[i]>>pw[i];
        
    }
    for(int i=0;i<m;i++)v.pb(i);
    int ans=INT_MAX;
    do{
        if(v[m-1]!=1 or v[0]!=0)continue;
        
        int s=0;
        bool u=0;
        for(int i=0;i<m-1;i++){
            int k=abs(cur[v[i]]-cur[v[i+1]]);
            int h=k/pw[i];
            if(k%pw[i])u=1;
           
            s+=h;
        };
        
        if(u==0)ans=min(ans,s);
        
    }while(next_permutation(v.begin(),v.end()));
    if(ans==INT_MAX){
        cout<<-1;
    }
    else{
        cout<<ans;
    }
    
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -