답안 #487378

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
487378 2021-11-15T10:53:35 Z LptN21 스파이 (JOI13_spy) C++14
100 / 100
201 ms 24632 KB
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define PI acos(-1.0)
#define FF first
#define SS second
#define eps 1e-3
// vector
#define pb push_back
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define lb lower_bound
#define ub upper_bound
// bit
#define CNTBIT(x) __builtin_popcount(x)
#define ODDBIT(x) __builtin_parity(x)
#define MASK(i) (1ll<<(i))
#define BIT(x, i) (((x)>>(i))&1)
#define SUBSET(big, small) (((big)&(small))==(small))
#define MINBIT(x) (x)&(-x)
// typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, int> ii;
typedef pair<int, ii> i3;
/* CODE BELOW */
const int N=2000+7, M=17+1, K=243+1;
const int MOD=1e9+7;
const int oo=1e9+7;

int n, m, k, t;

int _dp[N][N];
int p[N][2];
bool mark[N][N];

int solve(int u, int v) {
    if(mark[u][v]) return _dp[u][v];
    int ans=0; mark[u][v]=1;
    if(p[u][0]) ans+=solve(p[u][0], v);
    if(p[v][1]) ans+=solve(u, p[v][1]);

    // remove same
    if(p[u][0]&&p[v][1]) ans-=solve(p[u][0], p[v][1]);

    return _dp[u][v]+=ans;
}

signed main() {
    //freopen("test.inp", "r", stdin);
    //freopen("test.out", "w", stdout);
    //fastIO;
    scanf("%d%d", &n, &m);
    for(int i=1;i<=n;i++)
        for(int j=0;j<2;j++)
            scanf("%d", &p[i][j]);
    memset(_dp, 0, sizeof _dp);

    int u, v;
    for(int i=1;i<=m;i++) {
        scanf("%d%d", &u, &v);
        _dp[u][v]++;
    }

    for(int i=1;i<=n;i++) {
        printf("%d\n", solve(i, i));
    }

    return 0;
}
/* stuff you should look for
    - int overflow, array bounds
    - special/edge cases (n=1?)
    - do smth instead of nothing and stay organized
    - WRITE STUFF DOWN
    - DONT JUST STICK ON ONE APPROACH
*/

Compilation message

spy.cpp: In function 'int main()':
spy.cpp:54:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
spy.cpp:57:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |             scanf("%d", &p[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~~
spy.cpp:62:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         scanf("%d%d", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 16460 KB Output is correct
2 Correct 8 ms 16464 KB Output is correct
3 Correct 7 ms 16464 KB Output is correct
4 Correct 6 ms 16464 KB Output is correct
5 Correct 7 ms 16464 KB Output is correct
6 Correct 9 ms 16404 KB Output is correct
7 Correct 8 ms 16464 KB Output is correct
8 Correct 7 ms 16464 KB Output is correct
9 Correct 7 ms 16080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 20104 KB Output is correct
2 Correct 79 ms 20260 KB Output is correct
3 Correct 10 ms 19956 KB Output is correct
4 Correct 10 ms 19920 KB Output is correct
5 Correct 15 ms 20060 KB Output is correct
6 Correct 14 ms 20048 KB Output is correct
7 Correct 94 ms 19928 KB Output is correct
8 Correct 19 ms 20028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 174 ms 20036 KB Output is correct
2 Correct 159 ms 24408 KB Output is correct
3 Correct 83 ms 24392 KB Output is correct
4 Correct 93 ms 24632 KB Output is correct
5 Correct 112 ms 24368 KB Output is correct
6 Correct 82 ms 23860 KB Output is correct
7 Correct 201 ms 24372 KB Output is correct
8 Correct 136 ms 24248 KB Output is correct