답안 #970634

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
970634 2024-04-27T01:39:32 Z Requiem Drzava (COCI15_drzava) C++17
0 / 160
35 ms 44296 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 = 3e5 + 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[MAXN];
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;
                // 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);
        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:70:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   70 | main()
      | ^~~~
drzava.cpp: In function 'int main()':
drzava.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |         freopen(TASKNAME".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
drzava.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |         freopen(TASKNAME".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 8540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 8540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 8536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 8540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 8540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 8536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8660 KB Output is correct
2 Incorrect 35 ms 16728 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 8540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Runtime error 27 ms 39676 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 8536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Runtime error 31 ms 44296 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 8540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 8792 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 8540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 8692 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 8540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Runtime error 30 ms 44180 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 8536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Runtime error 29 ms 44124 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 8796 KB Output isn't correct
2 Halted 0 ms 0 KB -