답안 #713883

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
713883 2023-03-23T06:59:28 Z gaga999 Team Contest (JOI22_team) C++17
100 / 100
976 ms 77128 KB
#include <cstdio>
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stdlib.h>
#include <cstring>
#include <string.h>
#include <string>
#include <sstream>
#include <assert.h>
#include <climits>
#include <sstream>
#include <numeric>
#include <time.h>
#include <limits.h>
#include <list>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <iomanip>
#include <complex>
#include <chrono>
// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx,avx2,bmi,bmi2,lzcnt,popcnt")
#define lowbit(x) ((x) & -(x))
#define ml(a, b) ((1ll * (a) * (b)) % M)
#define tml(a, b) (a) = ((1ll * (a) * (b)) % M)
#define ad(a, b) ((0ll + (a) + (b)) % M)
#define tad(a, b) (a) = ((0ll + (a) + (b)) % M)
#define mi(a, b) ((0ll + M + (a) - (b)) % M)
#define tmi(a, b) (a) = ((0ll + M + (a) - (b)) % M)
#define tmin(a, b) (a) = min((a), (b))
#define tmax(a, b) (a) = max((a), (b))
#define iter(a) (a).begin(), (a).end()
#define riter(a) (a).rbegin(), (a).rend()
#define init(a, b) memset((a), (b), sizeof(a))
#define cpy(a, b) memcpy((a), (b), sizeof(a))
#define uni(a) a.resize(unique(iter(a)) - a.begin())
#define pb push_back
#define mpr make_pair
#define ls(i) ((i) << 1)
#define rs(i) ((i) << 1 | 1)
#define INF 0x3f3f3f3f
#define eps 1e-9
#define F first
#define S second
#define N 150005
#define AC cin.tie(0)->sync_with_stdio(0)
using namespace std;
typedef long long llt;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<llt, llt> pll;
typedef complex<double> cd;
// const int M = 998244353;

// random_device rm;
// mt19937 rg(rm());
// default_random_engine rg(rm());
// uniform_int_distribution<int> rd(INT_MIN, INT_MAX);
// uniform_real_distribution<double> rd(0, M_PI);

void db() { cout << "\n"; }
template <class T, class... U>
void db(T a, U... b) { cout << a << " ", db(b...); }

int xa, xb, xc, ct[N], a[N], b[N], c[N];
map<int, vector<int>> ma, mb, mc;
map<int, int> pa, pb, pc;
queue<int> q;
bool vd[N];

signed main()
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d%d%d", &a[i], &b[i], &c[i]);
        ma[a[i]].pb(i), mb[b[i]].pb(i), mc[c[i]].pb(i);
        pa[a[i]]++, pb[b[i]]++, pc[c[i]]++;
        tmax(xa, a[i]), tmax(xb, b[i]), tmax(xc, c[i]);
    }
    for (int i = 0; i < n; i++)
    {
        ct[i] += (xa == a[i]) + (xb == b[i]) + (xc == c[i]);
        if (ct[i] > 1)
            q.push(i), vd[i] = 1;
    }
    while (!q.empty())
    {
        int cr = q.front();
        q.pop(), n--;
        if (!--pa[a[cr]])
        {
            pa.erase(a[cr]), ma.erase(a[cr]);
            auto it = ma.rbegin();
            if (it != ma.rend() && xa > it->F)
            {
                xa = pa.rbegin()->F;
                assert(xa == it->F);
                for (int i : it->S)
                    if (++ct[i] > 1 && !vd[i])
                        vd[i] = 1, q.push(i);
            }
        }
        if (!--pb[b[cr]])
        {
            pb.erase(b[cr]), mb.erase(b[cr]);
            auto it = mb.rbegin();
            if (it != mb.rend() && xb > it->F)
            {
                xb = pb.rbegin()->F;
                assert(xb == it->F);
                for (int i : it->S)
                    if (++ct[i] > 1 && !vd[i])
                        vd[i] = 1, q.push(i);
            }
        }
        if (!--pc[c[cr]])
        {
            pc.erase(c[cr]), mc.erase(c[cr]);
            auto it = mc.rbegin();
            if (it != mc.rend() && xc > it->F)
            {
                xc = pc.rbegin()->F;
                assert(xc == it->F);
                for (int i : it->S)
                    if (++ct[i] > 1 && !vd[i])
                        vd[i] = 1, q.push(i);
            }
        }
    }
    if (n >= 3)
        printf("%d\n", xa + xb + xc);
    else
        puts("-1");
}

Compilation message

team.cpp: In function 'int main()':
team.cpp:86:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
team.cpp:89:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |         scanf("%d%d%d", &a[i], &b[i], &c[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 264 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 352 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 264 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 352 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 8 ms 2260 KB Output is correct
27 Correct 7 ms 1492 KB Output is correct
28 Correct 7 ms 1364 KB Output is correct
29 Correct 7 ms 1184 KB Output is correct
30 Correct 7 ms 1100 KB Output is correct
31 Correct 5 ms 852 KB Output is correct
32 Correct 4 ms 468 KB Output is correct
33 Correct 5 ms 852 KB Output is correct
34 Correct 9 ms 2260 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 5 ms 980 KB Output is correct
38 Correct 5 ms 980 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 224 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 48 ms 4936 KB Output is correct
12 Correct 31 ms 3572 KB Output is correct
13 Correct 33 ms 3864 KB Output is correct
14 Correct 52 ms 5276 KB Output is correct
15 Correct 45 ms 5272 KB Output is correct
16 Correct 39 ms 5088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 224 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 48 ms 4936 KB Output is correct
12 Correct 31 ms 3572 KB Output is correct
13 Correct 33 ms 3864 KB Output is correct
14 Correct 52 ms 5276 KB Output is correct
15 Correct 45 ms 5272 KB Output is correct
16 Correct 39 ms 5088 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 55 ms 4736 KB Output is correct
23 Correct 49 ms 4688 KB Output is correct
24 Correct 45 ms 3916 KB Output is correct
25 Correct 64 ms 5120 KB Output is correct
26 Correct 51 ms 5252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 224 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 48 ms 4936 KB Output is correct
12 Correct 31 ms 3572 KB Output is correct
13 Correct 33 ms 3864 KB Output is correct
14 Correct 52 ms 5276 KB Output is correct
15 Correct 45 ms 5272 KB Output is correct
16 Correct 39 ms 5088 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 55 ms 4736 KB Output is correct
23 Correct 49 ms 4688 KB Output is correct
24 Correct 45 ms 3916 KB Output is correct
25 Correct 64 ms 5120 KB Output is correct
26 Correct 51 ms 5252 KB Output is correct
27 Correct 1 ms 352 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 4 ms 596 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 88 ms 4792 KB Output is correct
35 Correct 96 ms 5664 KB Output is correct
36 Correct 118 ms 5764 KB Output is correct
37 Correct 131 ms 5464 KB Output is correct
38 Correct 60 ms 5448 KB Output is correct
39 Correct 36 ms 3432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 224 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 48 ms 4936 KB Output is correct
12 Correct 31 ms 3572 KB Output is correct
13 Correct 33 ms 3864 KB Output is correct
14 Correct 52 ms 5276 KB Output is correct
15 Correct 45 ms 5272 KB Output is correct
16 Correct 39 ms 5088 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 55 ms 4736 KB Output is correct
23 Correct 49 ms 4688 KB Output is correct
24 Correct 45 ms 3916 KB Output is correct
25 Correct 64 ms 5120 KB Output is correct
26 Correct 51 ms 5252 KB Output is correct
27 Correct 1 ms 352 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 4 ms 596 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 88 ms 4792 KB Output is correct
35 Correct 96 ms 5664 KB Output is correct
36 Correct 118 ms 5764 KB Output is correct
37 Correct 131 ms 5464 KB Output is correct
38 Correct 60 ms 5448 KB Output is correct
39 Correct 36 ms 3432 KB Output is correct
40 Correct 6 ms 1108 KB Output is correct
41 Correct 6 ms 852 KB Output is correct
42 Correct 3 ms 980 KB Output is correct
43 Correct 4 ms 992 KB Output is correct
44 Correct 228 ms 7752 KB Output is correct
45 Correct 242 ms 7280 KB Output is correct
46 Correct 213 ms 7860 KB Output is correct
47 Correct 232 ms 7468 KB Output is correct
48 Correct 95 ms 6444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 264 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 352 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 8 ms 2260 KB Output is correct
27 Correct 7 ms 1492 KB Output is correct
28 Correct 7 ms 1364 KB Output is correct
29 Correct 7 ms 1184 KB Output is correct
30 Correct 7 ms 1100 KB Output is correct
31 Correct 5 ms 852 KB Output is correct
32 Correct 4 ms 468 KB Output is correct
33 Correct 5 ms 852 KB Output is correct
34 Correct 9 ms 2260 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 5 ms 980 KB Output is correct
38 Correct 5 ms 980 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 224 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 48 ms 4936 KB Output is correct
51 Correct 31 ms 3572 KB Output is correct
52 Correct 33 ms 3864 KB Output is correct
53 Correct 52 ms 5276 KB Output is correct
54 Correct 45 ms 5272 KB Output is correct
55 Correct 39 ms 5088 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 55 ms 4736 KB Output is correct
62 Correct 49 ms 4688 KB Output is correct
63 Correct 45 ms 3916 KB Output is correct
64 Correct 64 ms 5120 KB Output is correct
65 Correct 51 ms 5252 KB Output is correct
66 Correct 1 ms 352 KB Output is correct
67 Correct 1 ms 340 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 4 ms 596 KB Output is correct
71 Correct 1 ms 468 KB Output is correct
72 Correct 2 ms 468 KB Output is correct
73 Correct 88 ms 4792 KB Output is correct
74 Correct 96 ms 5664 KB Output is correct
75 Correct 118 ms 5764 KB Output is correct
76 Correct 131 ms 5464 KB Output is correct
77 Correct 60 ms 5448 KB Output is correct
78 Correct 36 ms 3432 KB Output is correct
79 Correct 6 ms 1108 KB Output is correct
80 Correct 6 ms 852 KB Output is correct
81 Correct 3 ms 980 KB Output is correct
82 Correct 4 ms 992 KB Output is correct
83 Correct 228 ms 7752 KB Output is correct
84 Correct 242 ms 7280 KB Output is correct
85 Correct 213 ms 7860 KB Output is correct
86 Correct 232 ms 7468 KB Output is correct
87 Correct 95 ms 6444 KB Output is correct
88 Correct 976 ms 73012 KB Output is correct
89 Correct 813 ms 45584 KB Output is correct
90 Correct 759 ms 50516 KB Output is correct
91 Correct 751 ms 38808 KB Output is correct
92 Correct 629 ms 20424 KB Output is correct
93 Correct 951 ms 46924 KB Output is correct
94 Correct 749 ms 31560 KB Output is correct
95 Correct 299 ms 26132 KB Output is correct
96 Correct 599 ms 77128 KB Output is correct
97 Correct 54 ms 9132 KB Output is correct
98 Correct 186 ms 29296 KB Output is correct
99 Correct 194 ms 29456 KB Output is correct