제출 #321577

#제출 시각아이디문제언어결과실행 시간메모리
321577minoumJakarta Skyscrapers (APIO15_skyscraper)C++17
57 / 100
1034 ms2540 KiB
#include<bits/stdc++.h>

using namespace std;
typedef long long int ll;

const int MAXN = 3e4 + 5, inf = INT_MAX / 2;
int n, m, b[MAXN], p[MAXN], d[MAXN], cnt[MAXN], sz = 0;
bool wasmn[MAXN];
vector <int> ps[MAXN];

int findmn(){
	ll mn = inf, ind = -1;
	for(int i = 0; i < n; i++)
		if(!wasmn[i] && d[i] < mn) mn = d[i], ind = i;
	return ind;
}

void dij(){
	for(int i = 0; i < n; i++) d[i] = inf;
	d[b[0]] = 0;
	for(int h = 0; h < n; h++){
		int u = findmn();
		wasmn[u] = true;
		if(u == b[1] || d[u] >= inf) return;
		for(auto k: ps[u]){
			for(int i = u % k; i < n; i += k)
				if(i != u && cnt[i] && d[i] > d[u] + (abs(u - i) / k)) d[i] = d[u] + (abs(u - i) / k);
		}
	}
	return;
}

int main()
{
//	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//	cin >> n >> m;
	scanf("%d", &n); scanf("%d", &m);
	for(int i = 0; i < m; i++){
//		cin >> b[i] >> p[i];
		scanf("%d", b+i); scanf("%d", p+i);
		cnt[b[i]]++;
		ps[b[i]].push_back({p[i]});
	}
	dij();
//	cout << ((d[b[1]] >= inf)?-1:d[b[1]]) << '\n';
	if(d[b[1]] >= inf) printf("%d", -1);
	else printf("%d", d[b[1]]);
	return 0; 
}

컴파일 시 표준 에러 (stderr) 메시지

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   37 |  scanf("%d", &n); scanf("%d", &m);
      |  ~~~~~^~~~~~~~~~
skyscraper.cpp:37:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   37 |  scanf("%d", &n); scanf("%d", &m);
      |                   ~~~~~^~~~~~~~~~
skyscraper.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   40 |   scanf("%d", b+i); scanf("%d", p+i);
      |   ~~~~~^~~~~~~~~~~
skyscraper.cpp:40:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   40 |   scanf("%d", b+i); scanf("%d", p+i);
      |                     ~~~~~^~~~~~~~~~~
#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...