Submission #582371

# Submission time Handle Problem Language Result Execution time Memory
582371 2022-06-23T16:56:52 Z keta_tsimakuridze Sirni (COCI17_sirni) C++14
0 / 140
360 ms 333036 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define endl "\n"
const int N = 1e5 + 5, M = 1e7, mod = 1e9 + 7; //!
int t, p[N], last[M + 2], id[M + 5];
vector<pair<int,int> > E[M + 5];
int find(int u) {
	return (p[u] == u ? u : p[u] = find(p[u]));
}
bool merge(int u,int v) {
	u = find(u), v = find(v);
	if(u == v) return 0;
	p[u] = v;
	return 1;
}
main() {
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	int n;
	cin >> n;
	vector<int> x;
	for(int i = 1; i <= n; i++) {
		int a; cin >> a;
		x.push_back(a);
	}
	sort(x.begin(), x.end());
	x.erase(unique(x.begin(), x.end()), x.end());
	for(int i = 0; i < x.size(); i++) {
		id[x[i]] = i;
		last[x[i]] = x[i];
		p[i] = i;
	}
	for(int i = M; i >= 0; i--)  {
		if(!last[i]) last[i] = last[i + 1];
	}
	for(int i = 0; i < x.size(); i++) {
		for(int j = 0; j <= M; j += x[i]) {
			if(!last[j]) break;
			E[last[j] % x[i]].push_back({id[x[i]], id[last[j]]});
		}
	}
	ll ans = 0;
	for(int i = 0; i <= M; i++) {
		for(int j = 0; j < E[i].size(); j++) {
			int u = E[i][j].f, v = E[i][j].s;
			ans += (ll)i * merge(u, v);
		}
	}
	cout << ans;
}

Compilation message

sirni.cpp:20:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   20 | main() {
      | ^~~~
sirni.cpp: In function 'int main()':
sirni.cpp:31:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |  for(int i = 0; i < x.size(); i++) {
      |                 ~~^~~~~~~~~~
sirni.cpp:39:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |  for(int i = 0; i < x.size(); i++) {
      |                 ~~^~~~~~~~~~
sirni.cpp:47:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |   for(int j = 0; j < E[i].size(); j++) {
      |                  ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 190 ms 278012 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 180 ms 274352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 189 ms 278244 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 327 ms 290036 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 190 ms 280524 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 360 ms 302336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 205 ms 279248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 360 ms 328392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 354 ms 333036 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 208 ms 310988 KB Output isn't correct
2 Halted 0 ms 0 KB -