37922023-03-02 22:22:16SleepyOverlordBürokrácia (40)cpp17Elfogadva 40/4067ms15532 KiB
#include <vector>
#include <string> 
#include <set> 
#include <map> 
#include <unordered_set>
#include <unordered_map>
#include <queue> 
#include <bitset> 
#include <stack>
#include <list>

#include <numeric> 
#include <algorithm> 
#include <random>
#include <chrono>

#include <cstdio>
#include <fstream>
#include <iostream> 
#include <sstream> 
#include <iomanip>
#include <climits>

#include <cctype>
#include <cmath> 
#include <ctime>
#include <cassert>

using namespace std;

#define ULL unsigned long long
#define LL long long
#define PII pair <int, int>
#define VB vector <bool>
#define VI vector <int>
#define VLL vector <LL>
#define VD vector <double>
#define VS vector <string>
#define VPII vector <pair <int, int> >
#define VVI vector < VI >
#define VVB vector < VB >
#define SI set < int >
#define USI unordered_set <int>
#define MII map <int, int>
#define UMII unordered_map <int, int>
#define MS multiset
#define US unordered_set
#define UM unordered_map
#define UMS unordered_multiset
#define UMM unordered_multimap

#define FORN(i, n) for(int i = 0; i < (n); ++i)
#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 SZ size()
#define BG begin() 
#define EN end() 
#define CL clear()
#define X first
#define Y second
#define RS resize
#define PB push_back
#define MP make_pair
#define ALL(x) x.begin(), x.end()
#define INS insert
#define ER erase
#define CNT count

#define IN_FILE "a.in"
#define OUT_FILE "a.out"

template <typename T>
void PR(T var1)
{
	cout << var1 <<endl;
}
template <typename T, typename... Types>
void PR(T var1, Types... var2)
{
	cout << var1;
	PR(var2...);
}

int n;
VI a;
VB active;
VVI g;

int main()
{
	//freopen(IN_FILE, "r", stdin);
	//freopen(OUT_FILE, "w", stdout);

	cin >> n;
	a.RS(n + 1);
	g.RS(n + 1);
	FOR(i, 1, n)
	{
		string s;
		cin >> s;
		if (s == "V")
		{
			int x;
			cin >> x;
			a[i] = x;
			g[x].PB(i);
		}
	}
	active.RS(n + 1);
	int nActive = 0;
	FORD(i, n, 1)
		if (g[i].SZ == 0)
		{
			active[i] = true;
			++nActive;
		}
		else
		{
			bool valid = true;
			for (int j : g[i])
				if (active[j])
				{
					valid = false;
				}
			if (valid)
			{
				active[i] = true;
				++nActive;
			}
		}

	PR(nActive);
	FOR(i, 1, n)
		if (active[i]) cout << i << " ";

	return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base40/40
1Elfogadva0/03ms1684 KiB
2Elfogadva1/12ms1856 KiB
3Elfogadva1/13ms2068 KiB
4Elfogadva1/13ms2444 KiB
5Elfogadva1/130ms8000 KiB
6Elfogadva1/164ms14056 KiB
7Elfogadva1/161ms13668 KiB
8Elfogadva2/264ms12796 KiB
9Elfogadva2/264ms12356 KiB
10Elfogadva2/264ms12356 KiB
11Elfogadva2/264ms11796 KiB
12Elfogadva2/235ms9756 KiB
13Elfogadva2/235ms9880 KiB
14Elfogadva2/259ms12060 KiB
15Elfogadva2/250ms11568 KiB
16Elfogadva2/235ms10004 KiB
17Elfogadva2/235ms9880 KiB
18Elfogadva2/235ms10132 KiB
19Elfogadva2/230ms9624 KiB
20Elfogadva2/230ms9504 KiB
21Elfogadva2/230ms9428 KiB
22Elfogadva2/264ms15532 KiB
23Elfogadva4/467ms13324 KiB