답안 #687295

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
687295 2023-01-26T09:19:31 Z beedle Jakarta Skyscrapers (APIO15_skyscraper) C++17
0 / 100
1 ms 468 KB
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <set>
#include <iterator>
#include <stack>
#include <map>
#include <math.h>
#include <bitset>
#include <deque>
#include <string>
#include <tuple>
#include <queue>
#include <numeric>
#include <complex>
#include <assert.h>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define ld long long double
#define rep(i, a, b) for (long long i = a; i <= b; i++)
#define mod 1000000007ll
#define INF 1e18
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define all(x) (x).begin (), (x).end ()
#define sz(x) (ll) (x).size ()
#define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin())
#define rank rnk
#define log lg
#define fast                                                                  \
    ios_base::sync_with_stdio (false);                                        \
    cin.tie (NULL);                                                           \
    cout.tie (NULL)

using namespace std;

signed main()
{
    fast;

    ll n,m;
    cin>>n>>m;

    map <pair<ll,ll>,bool> mp;

    ll loc[m+1], p[m+1];
    set <ll> l[n];
    set <ll> lt;
    rep(i,1,m)
    {
    	cin>>loc[i]>>p[i];
    	mp[{p[i],loc[i]%p[i]}]=true;
    	l[p[i]].insert(loc[i]);
    	lt.insert(loc[i]);
   	}

    vector <pair<ll,ll>> adj[n];

    for(auto [pr,b]:mp)
    {
    	ll last=-1;
    	for(ll j=pr.ss;j<n;j+=pr.ff)
    	{
    		if(l[pr.ff].count(j))
    		{
    			if(last==-1)
    			last=j;
    			else
    			{
    				adj[last].pb({j,(j-last)/pr.ff});
    				adj[j].pb({last,(j-last)/pr.ff});
    				last=j;
    			}
    		}
    	}
    	last=-1;
    	ll f;
    	for(ll j=pr.ss;j<n;j+=pr.ff)
    	{
    		if(l[pr.ff].count(j))
    		{
				last=j;
    		}
    		else if(lt.count(j) && last!=-1)
    		{
    			adj[last].pb({j,(j-last)/pr.ff});
    		}
    		f=j;
    	}
    	last=-1;
    	for(ll j=f;j>=0;j-=pr.ff)
    	{
    		if(l[pr.ff].count(j))
    		{
    			last=j;
    		}
    		else if(lt.count(j) && last!=-1)
    		{
    			adj[last].pb({j,(last-j)/pr.ff});
    		}
    	}
    }

   	// rep(i,0,n-1)
   	// {
   		// cout<<i<<" : ";
   		// for(auto [a,b]:adj[i])
   		// cout<<a<<","<<b<<" ";
   		// cout<<endl;
   	// }

    vector <ll> d(n,INF);
    set <pair<ll,ll>> s;
    s.insert({0,loc[1]});
    d[loc[1]]=0;

    while(!s.empty())
    {
    	auto [dist,v]=(*s.begin());
    	s.erase({dist,v});
    	for(auto [u,e]:adj[v])
    	if(d[u]>e+d[v])
    	{
    		s.erase({d[u],u});
    		d[u]=e+d[v];
    		s.insert({d[u],u});
    	}
    }

    cout<<(d[loc[2]]==INF?-1:d[loc[2]])<<endl;
	
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:95:23: warning: 'f' may be used uninitialized in this function [-Wmaybe-uninitialized]
   95 |      for(ll j=f;j>=0;j-=pr.ff)
      |                       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 1 ms 340 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 1 ms 448 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Runtime error 1 ms 452 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 1 ms 468 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Runtime error 1 ms 340 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -