Submission #970636

# Submission time Handle Problem Language Result Execution time Memory
970636 2024-04-27T01:47:02 Z Requiem Drzava (COCI15_drzava) C++17
64 / 160
41 ms 52956 KB
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define MOD 1000000007
#define INF 1e18
#define fi first
#define se second
#define endl "\n"
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define sz(a) ((int)(a).size())
#define pi 3.14159265359
#define TASKNAME "drzava"
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; } 
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; } 
using namespace std; 
typedef pair<int,int> ii; 
typedef pair<int,ii> iii; 
typedef vector<int> vi; 
const int MAXN = 5e4 + 9;
struct point{
    int x, y, val;
    int distance(const point &other){
        return (x - other.x) * (x - other.x) + (y - other.y) * (y - other.y);
    }
};

struct edge{
    int a, b;
    int distance; //distance squared
};
point pt[MAXN];
edge e[1000009];
int n, k, par[MAXN], ranking[MAXN];
bitset<31> dp[MAXN];
bitset<31> tmp;
int root(int u){
    if (par[u] == u) return u;
    else return par[u] = root(par[u]);
}

void merge(int u,int v){
     tmp.reset();
     for(int i = 0; i < k; i++){
         for(int j = 0; j < k; j++){
             if (dp[u][i] and dp[v][j]) {
                tmp[(i + j) % k] = 1;
                tmp[i] = 1;
                tmp[j] = 1;
                // cout << (i + j) % k << endl;
             }
         }
     }

     for(int i = 0; i < k; i++){
         dp[u][i] = tmp[i];
     }
}
bool unite(int u,int v){
    u = root(u);
    v = root(v);
    if (u != v){
        if (ranking[u] < ranking[v]) swap(u, v);
        ranking[u] += ranking[v];
        par[v] = u;
        merge(u, v);
        // cout << dp[u] << endl;
        return dp[u][0];
    }
    return false;
}
main() 
{ 
    fast; 
   if (fopen(TASKNAME".inp","r")){
        freopen(TASKNAME".inp","r",stdin); 
        freopen(TASKNAME".out","w",stdout); 
   } 
   cin >> n >> k;
   for(int i = 1; i <= n; i++){
       cin >> pt[i].x >> pt[i].y >> pt[i].val;
       dp[i][pt[i].val % k] = 1;
   }
   int cnt = 0;

   iota(par + 1, par + 1 + n, 1);
   fill(ranking + 1, ranking + 1 + n, 1);
   for(int i = 1; i <= n; i++){
       for(int j = i + 1 ; j <= n; j++){
           e[++cnt] = {i, j, pt[i].distance(pt[j])};
       }
   }

   sort(e + 1, e + 1 + cnt, [&](const edge &a, const edge &b){
        return a.distance < b.distance;
   });


   int res = 0;
   for(int i = 1; i <= cnt; i++){
       int firstV = e[i].a;
       int secondV = e[i].b;
       if (unite(firstV, secondV)) {
           res = e[i].distance;
           break;
       }
   }

   cout << setprecision(3) << fixed << sqrt(res) << endl;

   
} 
/**
Warning:
- MLE / TLE?
- Gioi han mang?
- Gia tri max phai luon gan cho -INF
- long long co can thiet khong?
- tran mang.
- code can than hon
**/

Compilation message

drzava.cpp:73:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   73 | main()
      | ^~~~
drzava.cpp: In function 'int main()':
drzava.cpp:77:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |         freopen(TASKNAME".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
drzava.cpp:78:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |         freopen(TASKNAME".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 29 ms 12632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 27 ms 12792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 11 ms 8536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 26 ms 12636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 38 ms 16888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 10 ms 6620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Runtime error 33 ms 52892 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Runtime error 41 ms 52920 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Runtime error 32 ms 52784 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Runtime error 34 ms 52828 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Runtime error 39 ms 52824 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Runtime error 33 ms 52820 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Runtime error 33 ms 52828 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Runtime error 33 ms 52852 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Runtime error 36 ms 52780 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Runtime error 33 ms 52816 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Runtime error 34 ms 52820 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Runtime error 33 ms 52956 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -