This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "september.h"
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define ll long long int
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long int>
#define vvll vector<vector<long long int>>
#define pii pair<int, int>
#define vpii vector<pair<int, int>>
#define vpll vector<pair<long long int, long long int>>
#define pqpll priority_queue<pair<long long int, long long int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define mii map<int,int>
#define mll map<long long int, long long int>
#define mivi map<int,vector<int>>
#define f0r(i,n) for(int i=0;i<n;i++)
#define FOR(i,k,n) for(int i=k;i<n;i++)
using namespace __gnu_pbds;
using namespace std;
int solve(int N, int M, std::vector<int> F, std::vector<std::vector<int>> S) {
int ans = 0;
vvi nxt(N, vector<int>());
f0r(i, N){
if(i != 0)nxt[F[i]].pb(i);
}
vb vis(N, false);
vector<set<int>>pending(M);
queue<int>q;
f0r(i, N-1){
f0r(j, M){
if(vis[S[j][i]]){
pending[j].erase(S[j][i]);
}
else{
q.push(S[j][i]);
vis[S[j][i]] = 1;
f0r(k, M)if(j != k)pending[k].insert(S[j][i]);
while(!q.empty()){
int cur = q.front();
q.pop();
for(auto u : nxt[cur]){
if(vis[u])continue;
f0r(k, M)pending[k].insert(u);
vis[u] = 1;
q.push(u);
}
}
}
}
bool ok = 1;
f0r(j,M)if(!pending[j].empty())ok = 0;
if(ok)ans++;
}
/*
vi v = S[0];
int lo = N;
int ans = 0;
f0r(i, N-1){
//cout<<i<<'\n';
if(v[i] < lo){
for(int j = v[i]+1;j<lo;j++)pending.insert(j);
lo = v[i];
}
else{
pending.erase(v[i]);
}
if(pending.empty())ans++;
}
*/
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |