# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1211041 | loom | 9월 (APIO24_september) | C++20 | 0 ms | 0 KiB |
#include "september.h"
#include<bits/stdc++.h>
using namespace std;
int solve(int n, int m, vector<int> p, vector<vector<int>> s){
vector<int> cnt(n);
for(int i=1; i<n; i++) cnt[p[i]]++;
int ans = 0;
map<int,int> sz;
vector<int> v[m];
for(int i=0; i<n-1; i++){
for(int j=0; j<m; j++) v[j].push_back(s[j][i]);
int x = s[0][i];
if(cnt[x] == 0){
if(sz.count(p[x]) > 0 and --sz[p[x]] == 0) sz.erase(p[x]);
cnt[p[x]]--;
}
else{
sz[x] = cnt[x];
}
if(!sz.empty()) continue;
int tf = 1;
for(int j=0; j<m; j++){
sort(v[j].begin(), v[j].end());
if(v[j] != v[0]) tf = 0;
}
if(tf){
ans++;
for(int j=0; j<m; j++) v[j].clear();
}
}
return ans;
}