Submission #525650

# Submission time Handle Problem Language Result Execution time Memory
525650 2022-02-12T09:12:25 Z idas Regions (IOI09_regions) C++11
30 / 100
1000 ms 26152 KB
#include <bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr)
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define TSTS int ttt; cin >> ttt; while(ttt--) solve()
#define all(x) (x).begin(), (x).end()
#define le(vec) vec[vec.size()-1]
#define sz(x) ((int)((x).size()))
#define pb push_back
#define s second
#define f first

using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pdd;

const int INF=1e9, MOD=1e9+7, mod=998244353;
const ll LINF=1e18;

void setIO()
{
    FAST_IO;
}

void setIO(string s)
{
    FAST_IO;
    freopen((s+".in").c_str(), "r", stdin);
    freopen((s+".out").c_str(), "w", stdout);
}

const int N=2e5+10, R=510;
int n, r, q, up[R], gr[N], pre[R][R];
vi ad[N];

void dfs(int u)
{
    FOR(j, 1, r+1)
    {
        pre[j][gr[u]]+=up[j];
    }
    up[gr[u]]++;
    for(auto x : ad[u]){
        dfs(x);
    }
    up[gr[u]]--;
}

int main()
{
    setIO();
    cin >> n >> r >> q;
    cin >> gr[0];
    FOR(i, 1, n)
    {
        int s;
        cin >> s >> gr[i];
        ad[s-1].pb(i);
    }
    dfs(0);
    while(q--){
        int e1, e2;
        cin >> e1 >> e2;
        cout << pre[e1][e2] << endl;
    }
}

Compilation message

regions.cpp: In function 'void setIO(std::string)':
regions.cpp:32:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     freopen((s+".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
regions.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     freopen((s+".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4936 KB Output is correct
2 Correct 3 ms 4936 KB Output is correct
3 Correct 4 ms 4936 KB Output is correct
4 Correct 7 ms 5064 KB Output is correct
5 Correct 10 ms 5064 KB Output is correct
6 Correct 20 ms 5576 KB Output is correct
7 Correct 33 ms 5320 KB Output is correct
8 Correct 32 ms 5448 KB Output is correct
9 Correct 47 ms 5960 KB Output is correct
10 Correct 82 ms 6164 KB Output is correct
11 Correct 87 ms 6088 KB Output is correct
12 Correct 127 ms 6768 KB Output is correct
13 Correct 126 ms 6088 KB Output is correct
14 Correct 97 ms 6344 KB Output is correct
15 Correct 125 ms 8792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 718 ms 8600 KB Output is correct
2 Correct 922 ms 7368 KB Output is correct
3 Correct 1000 ms 10248 KB Output is correct
4 Runtime error 15 ms 15048 KB Execution killed with signal 11
5 Runtime error 18 ms 15956 KB Execution killed with signal 11
6 Runtime error 19 ms 16196 KB Execution killed with signal 11
7 Runtime error 24 ms 17212 KB Execution killed with signal 11
8 Runtime error 29 ms 19772 KB Execution killed with signal 11
9 Runtime error 43 ms 22272 KB Execution killed with signal 11
10 Runtime error 45 ms 24216 KB Execution killed with signal 11
11 Runtime error 56 ms 20824 KB Execution killed with signal 11
12 Runtime error 77 ms 25424 KB Execution killed with signal 11
13 Runtime error 51 ms 24308 KB Execution killed with signal 11
14 Runtime error 53 ms 23828 KB Execution killed with signal 11
15 Runtime error 51 ms 26012 KB Execution killed with signal 11
16 Runtime error 56 ms 26152 KB Execution killed with signal 11
17 Runtime error 52 ms 26048 KB Execution killed with signal 11