답안 #880778

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
880778 2023-11-30T03:41:03 Z WeIlIaN 스파이 (JOI13_spy) C++14
100 / 100
126 ms 20944 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <iomanip>
using namespace std;

#define MOD 1000000007
#define fir first
#define sec second
#define mp make_pair
#define pushf push_front
#define pushb push_back
#define popf pop_front
#define popb pop_back
#define all(a) a.begin(), a.end()

#define FOR(i, s, e) for(int i = s; i < e; i++)
#define RFOR(i, s, e) for(int i = e-1; i >= s; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)

#pragma GCC optimize(" unroll-loops")
#pragma gcc optimize("Ofast")
#pragma GCC optimization("Ofast")

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef vector<vpii> vvpii;
typedef vector<vpll> vvpll;
typedef queue<int> qi;
typedef queue<ll> qll;
typedef queue<pii> qpii;
typedef queue<pll> qpll;
typedef deque<int> dqi;
typedef deque<ll> dqll;
typedef deque<pii> dqpii;
typedef deque<pll> dqpll;  
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pqll;
typedef priority_queue<pii> pqpii;
typedef priority_queue<pll> pqpll;
typedef priority_queue<int, vi, greater<int> > r_pqi;
typedef priority_queue<ll, vll, greater<ll> > r_pqll;
typedef priority_queue<pii, vpii, greater<pii> > r_pqpii;
typedef priority_queue<pll, vpll, greater<pll> > r_pqpll;

vi child[2][2003];
int f[2003][2003], N, M, a, r, s, root[2];

void dfs1(int u) {
    for(auto v : child[0][u]) {
        for(int i = 0; i < N; i++) {
            f[v][i] += f[u][i];
        }
        dfs1(v);
    }
}

void dfs2(int u) {
    for(auto v : child[1][u]) {
        for(int i = 0; i < N; i++) {
            f[i][v] += f[i][u];
        }
        dfs2(v);
    }
}

int main() {
    scanf("%d%d", &N, &M);
    for(int i = 0; i < N; i++) {
        for(int j = 0; j <= 1; j++) {
            scanf("%d", &a);
            if(a == 0) root[j] = i; else child[j][--a].push_back(i);
        }
    }

    for(int i = 0; i < M; i++) {
        scanf("%d%d", &r, &s);
        f[--r][--s]++;
    }

    dfs1(root[0]);
    dfs2(root[1]);

    for(int i = 0; i < N; i++) {
        printf("%d\n", f[i][i]);
    }
    return 0;
}

Compilation message

spy.cpp:31: warning: ignoring '#pragma gcc optimize' [-Wunknown-pragmas]
   31 | #pragma gcc optimize("Ofast")
      | 
spy.cpp:32: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   32 | #pragma GCC optimization("Ofast")
      | 
spy.cpp:30:37: warning: bad option '-f unroll-loops' to pragma 'optimize' [-Wpragmas]
   30 | #pragma GCC optimize(" unroll-loops")
      |                                     ^
spy.cpp:70:16: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
   70 | void dfs1(int u) {
      |                ^
spy.cpp:79:16: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
   79 | void dfs2(int u) {
      |                ^
spy.cpp:88:10: warning: bad option '-f unroll-loops' to attribute 'optimize' [-Wattributes]
   88 | int main() {
      |          ^
spy.cpp: In function 'int main()':
spy.cpp:89:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |     scanf("%d%d", &N, &M);
      |     ~~~~~^~~~~~~~~~~~~~~~
spy.cpp:92:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |             scanf("%d", &a);
      |             ~~~~~^~~~~~~~~~
spy.cpp:98:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |         scanf("%d%d", &r, &s);
      |         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2904 KB Output is correct
8 Correct 1 ms 2592 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 16428 KB Output is correct
2 Correct 34 ms 16472 KB Output is correct
3 Correct 18 ms 16220 KB Output is correct
4 Correct 17 ms 16268 KB Output is correct
5 Correct 26 ms 16324 KB Output is correct
6 Correct 25 ms 16220 KB Output is correct
7 Correct 23 ms 16172 KB Output is correct
8 Correct 32 ms 16284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 16328 KB Output is correct
2 Correct 83 ms 20728 KB Output is correct
3 Correct 92 ms 20568 KB Output is correct
4 Correct 83 ms 20944 KB Output is correct
5 Correct 126 ms 20464 KB Output is correct
6 Correct 87 ms 20052 KB Output is correct
7 Correct 101 ms 20564 KB Output is correct
8 Correct 112 ms 20508 KB Output is correct