답안 #930393

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
930393 2024-02-19T14:24:53 Z boris_mihov 조이터에서 친구를 만드는건 재밌어 (JOI20_joitter2) C++17
1 / 100
51 ms 856 KB
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
#include <queue>
#include <set>
#include <map>

typedef long long llong;
const int MAXN = 50 + 10;
const int MAXM = 30000 + 10;
const int MOD = 1e9 + 7;

int n, m;
bool active[MAXN][MAXN];
int from[MAXM];
int to[MAXM];

void run()
{
    bool shouldCall = false;
    for (int x1 = 1 ; x1 <= n ; ++x1)
    {
        for (int x2 = 1 ; x2 <= n ; ++x2)
        {
            for (int x3 = 1 ; x3 <= n ; ++x3)
            {
                if (x1 == x2 || x2 == x3 || x1 == x3) continue;
                if (active[x1][x2] && active[x2][x3] && active[x3][x2] && !active[x1][x3])
                {
                    active[x1][x3] = true;
                    shouldCall = true;
                }
            }
        }
    }

    if (shouldCall)
    {
        run();
    }
}

int ans;
void calc()
{
    int res = 0;
    for (int x1 = 1 ; x1 <= n ; ++x1)
    {
        for (int x2 = 1 ; x2 <= n ; ++x2)
        {
            res += active[x1][x2];
        }
    }
    
    ans = res;
}

void solve()
{
    for (int i = 1 ; i <= m ; ++i)
    {
        bool shouldRun = !active[from[i]][to[i]];
        active[from[i]][to[i]] = true;
        if (shouldRun) 
        {
            run();
            calc();
        }

        std::cout << ans << '\n';
    }
}

void input()
{
    std::cin >> n >> m;
    for (int i = 1 ; i <= m ; ++i)
    {
        std::cin >> from[i] >> to[i];
    }
}

void fastIOI()
{
    std::ios_base :: sync_with_stdio(0);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);
}

int main()
{
    fastIOI();
    input();
    solve();

    return 0;
}

/*
14 13
10 14
3 10
14 13
1 3
3 5
3 11
12 14
14 6
11 8
2 3
7 8
9 7
1 4

5 6
4 2
1 5
2 3
2 5
3 2
3 1
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 45 ms 348 KB Output is correct
8 Correct 43 ms 344 KB Output is correct
9 Correct 41 ms 348 KB Output is correct
10 Correct 37 ms 348 KB Output is correct
11 Correct 36 ms 344 KB Output is correct
12 Correct 37 ms 348 KB Output is correct
13 Correct 37 ms 348 KB Output is correct
14 Correct 39 ms 348 KB Output is correct
15 Correct 42 ms 344 KB Output is correct
16 Correct 42 ms 464 KB Output is correct
17 Correct 36 ms 344 KB Output is correct
18 Correct 36 ms 348 KB Output is correct
19 Correct 40 ms 600 KB Output is correct
20 Correct 42 ms 344 KB Output is correct
21 Correct 51 ms 348 KB Output is correct
22 Correct 46 ms 604 KB Output is correct
23 Correct 36 ms 344 KB Output is correct
24 Correct 41 ms 348 KB Output is correct
25 Correct 38 ms 344 KB Output is correct
26 Correct 23 ms 348 KB Output is correct
27 Correct 23 ms 464 KB Output is correct
28 Correct 31 ms 348 KB Output is correct
29 Correct 31 ms 348 KB Output is correct
30 Correct 36 ms 348 KB Output is correct
31 Correct 36 ms 488 KB Output is correct
32 Correct 40 ms 344 KB Output is correct
33 Correct 38 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 45 ms 348 KB Output is correct
8 Correct 43 ms 344 KB Output is correct
9 Correct 41 ms 348 KB Output is correct
10 Correct 37 ms 348 KB Output is correct
11 Correct 36 ms 344 KB Output is correct
12 Correct 37 ms 348 KB Output is correct
13 Correct 37 ms 348 KB Output is correct
14 Correct 39 ms 348 KB Output is correct
15 Correct 42 ms 344 KB Output is correct
16 Correct 42 ms 464 KB Output is correct
17 Correct 36 ms 344 KB Output is correct
18 Correct 36 ms 348 KB Output is correct
19 Correct 40 ms 600 KB Output is correct
20 Correct 42 ms 344 KB Output is correct
21 Correct 51 ms 348 KB Output is correct
22 Correct 46 ms 604 KB Output is correct
23 Correct 36 ms 344 KB Output is correct
24 Correct 41 ms 348 KB Output is correct
25 Correct 38 ms 344 KB Output is correct
26 Correct 23 ms 348 KB Output is correct
27 Correct 23 ms 464 KB Output is correct
28 Correct 31 ms 348 KB Output is correct
29 Correct 31 ms 348 KB Output is correct
30 Correct 36 ms 348 KB Output is correct
31 Correct 36 ms 488 KB Output is correct
32 Correct 40 ms 344 KB Output is correct
33 Correct 38 ms 348 KB Output is correct
34 Runtime error 10 ms 856 KB Execution killed with signal 11
35 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 45 ms 348 KB Output is correct
8 Correct 43 ms 344 KB Output is correct
9 Correct 41 ms 348 KB Output is correct
10 Correct 37 ms 348 KB Output is correct
11 Correct 36 ms 344 KB Output is correct
12 Correct 37 ms 348 KB Output is correct
13 Correct 37 ms 348 KB Output is correct
14 Correct 39 ms 348 KB Output is correct
15 Correct 42 ms 344 KB Output is correct
16 Correct 42 ms 464 KB Output is correct
17 Correct 36 ms 344 KB Output is correct
18 Correct 36 ms 348 KB Output is correct
19 Correct 40 ms 600 KB Output is correct
20 Correct 42 ms 344 KB Output is correct
21 Correct 51 ms 348 KB Output is correct
22 Correct 46 ms 604 KB Output is correct
23 Correct 36 ms 344 KB Output is correct
24 Correct 41 ms 348 KB Output is correct
25 Correct 38 ms 344 KB Output is correct
26 Correct 23 ms 348 KB Output is correct
27 Correct 23 ms 464 KB Output is correct
28 Correct 31 ms 348 KB Output is correct
29 Correct 31 ms 348 KB Output is correct
30 Correct 36 ms 348 KB Output is correct
31 Correct 36 ms 488 KB Output is correct
32 Correct 40 ms 344 KB Output is correct
33 Correct 38 ms 348 KB Output is correct
34 Runtime error 10 ms 856 KB Execution killed with signal 11
35 Halted 0 ms 0 KB -