답안 #490199

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
490199 2021-11-26T08:58:44 Z Killer2501 Sirni (COCI17_sirni) C++14
0 / 140
290 ms 295752 KB
#include<bits/stdc++.h>
#define pll pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define task "test"
#define pii pair<pll, pll>
using namespace std;
using ll = int;
const int  N = 1e5+5;
const ll mod = 1e8+7;
const ll base = 113;
const ll inf = 1e9;
ll m, n, t, k, a[N], tong, d[N], b[N], h[N], ans, near[N*100];
vector<pll> adj[N*100];
vector<ll> kq, ask[N];
vector<pll> val;
ll pw(ll k, ll n, ll md)
{
	ll total = 1;
	for(; n; n >>= 1)
	{
		if(n&1)total = total * k % md;
		k = k * k % md;
	}
	return total;
}
struct DSU
{
    ll n;
    vector<ll> lab;
    DSU(ll _n)
    {
        n = _n;
        lab.resize(n+1, -1);
    }
    ll findp(ll u)
    {
        return lab[u] < 0 ? u : lab[u] = findp(lab[u]);
    }
    bool hop(ll u, ll v)
    {
        u = findp(u);
        v = findp(v);
        if(u == v)return false;
        if(lab[u] > lab[v])swap(u, v);
        lab[u] += lab[v];
        lab[v] = u;
        return true;
    }
};
struct BIT
{
    ll n;
    vector<ll> fe;
    BIT(ll _n)
    {
        n = _n;
        fe.resize(n+1, 0);
    }
    void reset()
    {
        fill(fe.begin(), fe.end(), 0);
    }
    void add(ll id, ll x)
    {
        for(; id <= n; id += id & -id)fe[id] += x;
    }
    ll get(ll id)
    {
        ll total = 0;
        for(; id ; id -= id & -id)total += fe[id];
        return total;
    }
};
string s;
void sol()
{
    cin >> n;
    for(int i = 1; i <= n; i ++)
    {
        cin >> a[i];
        kq.pb(a[i]);
    }
    sort(kq.begin(), kq.end());
    kq.erase(unique(kq.begin(), kq.end()), kq.end());
    m = kq.back();
    for(int i = 0; i < kq.size(); i ++)
    {
        for(int j = t; j <= kq[i]; j ++)near[j] = i;
        t = kq[i];
    }
    for(int i = 0; i < kq.size()-1; i ++)
    {
        for(int j = kq[i]; j <= m; j += kq[i])
        {
            if(near[j] != i)
            {
                //cout << kq[i] <<" "<< kq[near[j]] << '\n';
                adj[kq[near[j]] % kq[i]].pb({near[j], i});
            }

        }
    }
    DSU dsu(kq.size());
    long long ans = 0;
    for(int i = 0; i <= m; i ++)
    {
        for(pll x: adj[i])
        {
            if(dsu.hop(x.fi, x.se))ans += i;
        }
    }
    cout << ans;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(fopen(task".inp", "r"))
    {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    int ntest = 1;
    //cin >> ntest;
    while(ntest -- > 0)
    sol();
}

Compilation message

sirni.cpp: In function 'void sol()':
sirni.cpp:88:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |     for(int i = 0; i < kq.size(); i ++)
      |                    ~~^~~~~~~~~~~
sirni.cpp:93:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |     for(int i = 0; i < kq.size()-1; i ++)
      |                    ~~^~~~~~~~~~~~~
sirni.cpp: In function 'int main()':
sirni.cpp:123:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  123 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sirni.cpp:124:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  124 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 140 ms 276676 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 118 ms 237576 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 141 ms 276720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 166 ms 252936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 124 ms 243528 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 232 ms 264604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 131 ms 242468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 280 ms 291484 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 290 ms 295752 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 175 ms 279204 KB Output isn't correct
2 Halted 0 ms 0 KB -