Submission #1262808

#TimeUsernameProblemLanguageResultExecution timeMemory
1262808SmuggingSpunSirni (COCI17_sirni)C++20
42 / 140
58 ms6580 KiB
#include<bits/stdc++.h>
#define taskname "E"
using namespace std;
typedef long long ll;
int n;
namespace sub1{
	void solve(){
		vector<int>a(n);
		for(int& x : a){
			cin >> x;
		}
		vector<int>p(n);
		iota(p.begin(), p.end(), 0);
		auto find_set = [&] (int u){
			while(u != p[u]){
				u = p[u] = p[p[u]];
			}	
			return u;
		};
		auto merge = [&] (int u, int v){
			if((u = find_set(u)) != (v = find_set(v))){
				p[u] = v;
				return true;
			}	
			return false;
		};
		vector<pair<int, pair<int, int>>>edge;
		for(int i = 0; i < n; i++){
			for(int j = i + 1; j < n; j++){
				edge.emplace_back(make_pair(min(a[i] % a[j], a[j] % a[i]), make_pair(i, j)));
			}
		}
		sort(edge.begin(), edge.end());
		ll ans = 0;
		for(auto& [w, e] : edge){
			if(merge(e.first, e.second)){
				ans += w;
			}
		}
		cout << ans;
	}
}
namespace sub23{
	void solve(){
		
	}
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	if(fopen(taskname".inp", "r")){
		freopen(taskname".inp", "r", stdin);
	}
	cin >> n;
	if(n <= 1000){
		sub1::solve();
	}
	else{
		sub23::solve();
	}
}

Compilation message (stderr)

sirni.cpp: In function 'int main()':
sirni.cpp:51:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |                 freopen(taskname".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...
#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...