#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
//#include <unistd.h>
//#include <fcntl.h>
using namespace std;
vector<vector<int>> spotkania;
int main() {
//dup2(open("/home/szachy-a/Pobrane/tests/07.in", 400), 0);
ios_base::sync_with_stdio(0);
cin.tie(0);
int nDni, nPierwszy;
cin >> nDni >> nPierwszy;
spotkania.resize(nDni);
spotkania[0].resize(nPierwszy, -1);
for (int dzien = 1; dzien < nDni; dzien++) {
int nSpotkan;
cin >> nSpotkan;
spotkania[dzien].resize(nSpotkan);
for (int i = 0; i < nSpotkan; i++) {
cin >> spotkania[dzien][i];
spotkania[dzien][i]--;
}
}
spotkania.push_back({});
reverse(spotkania.begin(), spotkania.end());
int* ilosciNaSpotkaniach = new int[500000];
int* prevIlosciNaSpotkaniach = new int[500000];
//vector<int> ilosciNaSpotkaniach(10);
//vector<int> prevIlosciNaSpotkaniach(10);
int totalZuzyte = 0, wolne = 0;
for (int dzien = 1; dzien <= nDni; dzien++) {
memset(ilosciNaSpotkaniach, 0, spotkania[dzien].size() * sizeof(int));
//ilosciNaSpotkaniach.clear();
//ilosciNaSpotkaniach.resize(10);
for (int i = 0; i < spotkania[dzien - 1].size(); i++) {
if (spotkania[dzien - 1][i] == -1) {
wolne += prevIlosciNaSpotkaniach[i];
}
else {
ilosciNaSpotkaniach[spotkania[dzien - 1][i]] += prevIlosciNaSpotkaniach[i];
}
}
for (int i = 0; i < spotkania[dzien].size(); i++) {
if (!ilosciNaSpotkaniach[i]) {
ilosciNaSpotkaniach[i] = 1;
if (wolne) {
wolne--;
}
else {
totalZuzyte++;
}
}
}
swap(ilosciNaSpotkaniach, prevIlosciNaSpotkaniach);
}
cout << totalZuzyte;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | #include <iostream> #include <vector> #include <algorithm> #include <cstring> //#include <unistd.h> //#include <fcntl.h> using namespace std; vector<vector<int>> spotkania; int main() { //dup2(open("/home/szachy-a/Pobrane/tests/07.in", 400), 0); ios_base::sync_with_stdio(0); cin.tie(0); int nDni, nPierwszy; cin >> nDni >> nPierwszy; spotkania.resize(nDni); spotkania[0].resize(nPierwszy, -1); for (int dzien = 1; dzien < nDni; dzien++) { int nSpotkan; cin >> nSpotkan; spotkania[dzien].resize(nSpotkan); for (int i = 0; i < nSpotkan; i++) { cin >> spotkania[dzien][i]; spotkania[dzien][i]--; } } spotkania.push_back({}); reverse(spotkania.begin(), spotkania.end()); int* ilosciNaSpotkaniach = new int[500000]; int* prevIlosciNaSpotkaniach = new int[500000]; //vector<int> ilosciNaSpotkaniach(10); //vector<int> prevIlosciNaSpotkaniach(10); int totalZuzyte = 0, wolne = 0; for (int dzien = 1; dzien <= nDni; dzien++) { memset(ilosciNaSpotkaniach, 0, spotkania[dzien].size() * sizeof(int)); //ilosciNaSpotkaniach.clear(); //ilosciNaSpotkaniach.resize(10); for (int i = 0; i < spotkania[dzien - 1].size(); i++) { if (spotkania[dzien - 1][i] == -1) { wolne += prevIlosciNaSpotkaniach[i]; } else { ilosciNaSpotkaniach[spotkania[dzien - 1][i]] += prevIlosciNaSpotkaniach[i]; } } for (int i = 0; i < spotkania[dzien].size(); i++) { if (!ilosciNaSpotkaniach[i]) { ilosciNaSpotkaniach[i] = 1; if (wolne) { wolne--; } else { totalZuzyte++; } } } swap(ilosciNaSpotkaniach, prevIlosciNaSpotkaniach); } cout << totalZuzyte; } |
English