Submission #1057385

#TimeUsernameProblemLanguageResultExecution timeMemory
1057385ljtunas스파이 (JOI13_spy)C++14
100 / 100
150 ms64852 KiB
#include <bits/stdc++.h>// "i will win voi25" using namespace std; #define fi first #define se second #define Forv(v, h) for(auto &v : h) #define For(i, a, b) for(int i = a; i <= b; ++i) #define Ford(i, a, b) for(int i = a; i >= b; --i) #define all(h) h.begin(), h.end() #define reset(h, v) (memset(h, v, sizeof(h))) #define c_bit(i) __builtin_popcountll(i) #define Bit(mask, i) ((mask >> i) & 1) #define onbit(mask, i) ((mask) bitor (1LL << i)) #define offbit(mask, i) ((mask) &~ (1LL << i)) using ll = long long; using ii = pair<ll, ll>; using vi = vector<ll>; using vvi = vector<vi>; using vii = vector<ii>; template <class X, class Y> bool maximize(X &a, const Y &b) { if(a < b) return a = b, true; return false; } template <class X, class Y> bool minimize(X &a, const Y &b) { if(a > b) return a = b, true; return false; } // #define int long long const int dx[] = {0, -1, +1, 0}, dy[] = {-1, 0, 0, +1}; const ll oo = 1e18 + 1, base = 311, block = 500; const ll MOD = 1e9 + 7; const int MAXN = 3e3 + 5; int n, m; int a[MAXN], b[MAXN], cnt[MAXN][MAXN], dp[MAXN][MAXN]; int solve (int i, int j) { if (!i || !j) return 0ll; if (~dp[i][j]) return dp[i][j]; int res = cnt[i][j]; res += solve(a[i], j) + solve(i, b[j]) - solve(a[i], b[j]); return dp[i][j] = res; } void process() { cin >> n >> m; For (i, 1, n) { cin >> a[i] >> b[i]; } reset(dp, -1); For (i, 1, m) { int x, y; cin >> x >> y; cnt[x][y]++; } For (i, 1, n) cout << solve(i, i) << '\n'; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); #define name "a" if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } //int tc = 1; cin >> tc; while (tc--) process(); // -> ac cerr << "\nTime elapsed: " << (1.0 * clock() / CLOCKS_PER_SEC) << " s.\n"; return 0; }

Compilation message (stderr)

spy.cpp: In function 'int32_t main()':
spy.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |         freopen(name".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
spy.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |         freopen(name".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...