# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1091598 |
2024-09-21T14:01:50 Z |
TgX_2 |
Sirni (COCI17_sirni) |
C++17 |
|
5000 ms |
269004 KB |
/*-----------------------------
Author : TgX.2
11Ti - K28 - CHV
-----------------------------*/
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i += 1)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; i -= 1)
#define FORC(i, a, b, c) for (int i = (a), _b = (b), _c = (c); i <= _b; i += _c)
#define fi first
#define se second
#define pb push_back
#define len(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define _ << " " <<
#define __ << "\n"
#define ______________TgX______________ main()
// #define int long long
#define intmax 1e9
#define intmin -1e9
#define llongmax 1e18
#define llongmin -1e18
#define memo(a, val) memset((a), (val), sizeof((a)))
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename T1, typename T2>
bool mini(T1 &a, T2 b)
{if (a > b) a = b; else return 0; return 1;}
template<typename T1, typename T2>
bool maxi(T1 &a, T2 b)
{if (a < b) a = b; else return 0; return 1;}
/*-----------------------------*/
const int maxn = 1e5 + 7;
int n, a[maxn];
bool vis[maxn];
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
map<int, int> candi;
void process() {
cin >> n;
FOR(i, 1, n) cin >> a[i];
q.push({0, 1});
int ans = 0;
while(!q.empty()) {
pair<int, int> top = q.top(); q.pop();
int u = top.se, cost = top.fi;
if (!vis[u]) {
vis[u] = 1;
ans += cost;
FOR(i, 1, n) if (!vis[i]) {
if (candi.find(a[i]) == candi.end())
candi[i] = min(a[i] % a[u], a[u] % a[i]);
if (min(a[i] % a[u], a[u] % a[i]) <= candi[i])
q.push({min(a[i] % a[u], a[u] % a[i]), i});
}
}
}
cout << ans;
}
/*-----------------------------*/
______________TgX______________ {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen("temp.inp", "r")) {
freopen("temp.inp", "r", stdin);
freopen("temp.out", "w", stdout);
}
process();
}
/*==============================+
|INPUT |
--------------------------------|
================================+
|OUTPUT |
--------------------------------|
===============================*/
Compilation message
sirni.cpp:21:41: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
21 | #define ______________TgX______________ main()
| ^~~~
sirni.cpp:80:1: note: in expansion of macro '______________TgX______________'
80 | ______________TgX______________ {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sirni.cpp: In function 'int main()':
sirni.cpp:84:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
84 | freopen("temp.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sirni.cpp:85:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
85 | freopen("temp.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
4556 KB |
Output is correct |
2 |
Correct |
93 ms |
4556 KB |
Output is correct |
3 |
Correct |
99 ms |
4556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
89 ms |
4532 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
4620 KB |
Output is correct |
2 |
Correct |
84 ms |
4548 KB |
Output is correct |
3 |
Correct |
95 ms |
4552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5037 ms |
268796 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5069 ms |
263808 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5043 ms |
268828 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5057 ms |
265112 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5094 ms |
269004 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5044 ms |
268780 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5029 ms |
264232 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |