Submission #881227

#TimeUsernameProblemLanguageResultExecution timeMemory
881227cpptowinJakarta Skyscrapers (APIO15_skyscraper)C++17
36 / 100
1094 ms65428 KiB
#include<bits/stdc++.h>
#define fo(i,d,c) for(int i=d;i<=c;i++)
#define fod(i,c,d) for(int i=c;i>=d;i--)
#define maxn 30010
#define N 1010
#define fi first
#define se second
#define pb emplace_back
#define en cout<<"\n";
#define int long long
#define inf (int)1e18
#define pii pair<int,int>
#define vii vector<pii>
#define lb(x) x&-x
#define bit(i,j) ((i>>j)&1)
#define offbit(i,j) (i^(1<<j))
#define onbit(i,j) (i|(1<<j))
#define vi vector<int>
template <typename T1, typename T2> bool minimize(T1 &a, T2 b){if (a > b) {a = b; return true;} return false;}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b){if (a < b) {a = b; return true;} return false;}
using namespace std;
int n,m;
pii a[maxn];
int d[maxn];
vii ke[maxn];
void dij(int inp)
{
    fo(i,1,m) d[i] = inf;
    d[inp] = 0;
    priority_queue<pii,vii,greater<pii>> q;
    q.push({0,inp});
    while(q.size())
    {
        auto [du,u] = q.top();
        q.pop();
        if(du != d[u]) continue;
        for(auto [v,w] : ke[u])
        {
            if(d[v] > d[u] + w)
            {
                d[v] = d[u] + w;
                q.push({d[v],v});
            }
        }
    }
}
main()
{
    #define name "TASK"
    if(fopen(name".inp","r"))
    {
       freopen(name".inp","r",stdin);
       freopen(name".out","w",stdout);
    }
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin >> n >> m;
    fo(i,1,m) cin >> a[i].fi >> a[i].se;
    fo(i,1,m) fo(j,1,m) if(i != j)
    {
        int val = abs(a[i].fi - a[j].fi);
        if(val % a[i].se == 0)
        ke[i].pb(j,val / a[i].se);
    }
    dij(1);
    cout << (d[2] >= inf ? -1 : d[2]);
}

Compilation message (stderr)

skyscraper.cpp:47:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   47 | main()
      | ^~~~
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:52:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |        freopen(name".inp","r",stdin);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:53:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |        freopen(name".out","w",stdout);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...