Submission #452085

# Submission time Handle Problem Language Result Execution time Memory
452085 2021-08-03T18:29:32 Z ZaZo_ Jakarta Skyscrapers (APIO15_skyscraper) C++14
10 / 100
1 ms 932 KB
//Sorry but iam targeting IOI :))
//NEVER LOSE HOPE
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
#define endl "\n"
#define int long long
#define ceil(a,b)   (a+(b-1))/b
#define all(v) v.begin(),v.end()
#define Hidden ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int mod = 1e9+7;
int32_t main()
{
  //freopen("dprime.in" , "r" , stdin);
  Hidden;
  int n, m;
  cin >> n >> m;
  pair<int,int>arr[n+1];
  vector<pair<int,int>>edges[n+1];
  vector<int>freq[n+1];
  for(int i = 0 ; i < m ; i ++)
  {
    int b , p;
    cin>>b>>p;
    arr[i]={b,p};
    freq[b].push_back(i);
  }
  for(int i = 0 ; i < m ; i++)
  {
    for(int j = arr[i].first+arr[i].second ; j<=n ; j+=arr[i].second)
    {
      for(int p = 0 ; p < freq[j].size() ; p ++)
      {
        edges[arr[i].first].push_back({arr[freq[j][p]].first ,(j-arr[i].first)/arr[i].second});
      }
    }
    for(int j = arr[i].first-arr[i].second ; j>=0 ; j-=arr[i].second)
    {
      for(int p = 0 ; p < freq[j].size() ; p ++)
      {
        edges[arr[i].first].push_back({arr[freq[j][p]].first ,(arr[i].first-j)/arr[i].second});
      }
    }
  }


  priority_queue<pair<int,int>>pq;
  pq.push({0,arr[0].first});
  int dist[30005];
  for(int i = 0 ; i < 30005 ; i++) dist[i]=INT_MAX;
  dist[arr[0].first]=0;
  while(!pq.empty())
  {
    pair<int,int>p=pq.top();
    pq.pop();
    for(int i = 0; i < edges[p.second].size() ; i++)
    {
      int cost=dist[p.second]+edges[p.second][i].second;
      if(dist[edges[p.second][i].first] > cost)
      {
        dist[edges[p.second][i].first] = cost;
        pq.push({-cost , edges[p.second][i].first});
      }
    }
  }
  if(dist[arr[1].first] == INT_MAX) cout<<"-1";
  else cout<<dist[arr[1].first];


}

Compilation message

skyscraper.cpp: In function 'int32_t main()':
skyscraper.cpp:33:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |       for(int p = 0 ; p < freq[j].size() ; p ++)
      |                       ~~^~~~~~~~~~~~~~~~
skyscraper.cpp:40:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |       for(int p = 0 ; p < freq[j].size() ; p ++)
      |                       ~~^~~~~~~~~~~~~~~~
skyscraper.cpp:57:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |     for(int i = 0; i < edges[p.second].size() ; i++)
      |                    ~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 0 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Runtime error 1 ms 844 KB Execution killed with signal 11
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Runtime error 1 ms 844 KB Execution killed with signal 11
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Runtime error 1 ms 844 KB Execution killed with signal 11
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Runtime error 1 ms 932 KB Execution killed with signal 11
11 Halted 0 ms 0 KB -