QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#572519 | #3942. Keyboards in Concert | LaVuna47# | AC ✓ | 66ms | 16916kb | C++17 | 2.7kb | 2024-09-18 15:06:35 | 2024-09-18 15:06:36 |
Judging History
answer
/** gnu specific **/
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/** contains everything I need in std **/
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(S) ((int)S.size())
#define FOR(i, n) for(int i = 0; i < n; ++i)
#define RFOR(i, n) for(int i = n-1; i >= 0; --i)
#define output_vec(vec) { FOR(i_, sz(vec)) cout << vec[i_] << ' '; cout << '\n'; }
#define x first
#define y second
#define pb push_back
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<bool> vb;
typedef short si;
typedef unsigned long long ull;
typedef long double LD;
typedef pair<ull, ull> pull;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
using namespace std;
#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif
const int INF = 1e9 + 47;
int solve()
{
int n, m;
if (!(cin >> n >> m))
return 1;
vector<set<int>> notes(n);
FOR (i, n)
{
int nn;
cin >> nn;
//notes[i].resize(nn);
FOR (j, nn)
{
int el;
cin >> el;
notes[i].insert(el);
}
}
vector<int> play(m);
FOR (i, m)
cin >> play[i];
vector dp(m, vector<int>(n, INF));
FOR (i, n)
if (notes[i].count(play[0]))
dp[0][i] = 0;
int mini = 0;
FOR (ii, m - 1)
{
int i = ii + 1;
FOR (j, n)
{
if (!notes[j].count(play[i]))
{
continue;
}
if (notes[j].count(play[i]))
dp[i][j] = min(dp[i][j], dp[i - 1][j]);
dp[i][j] = min(dp[i][j], dp[i - 1][mini] + 1);
}
int curmin = INF, curidx = -1;
FOR (j, n)
{
if (dp[i][j] < curmin)
{
curmin = dp[i][j];
curidx = j;
}
}
mini = curidx;
}
cout << *min_element(all(dp[m - 1])) << '\n';
return 0;
}
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int TET = 1e9;
//cin >> TET;
for (int i = 1; i <= TET; i++)
{
if (solve())
{
break;
}
#ifdef ONPC
cout << "__________________________" << endl;
#endif
}
#ifdef ONPC
cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
#endif
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3644kb
input:
2 10 2 1 2 2 2 3 1 2 1 2 3 3 2 3 1 3
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3740kb
input:
10 1000 44 5 38 8 11 26 59 42 86 51 19 54 76 4 34 36 18 75 84 23 0 37 22 55 1 29 60 10 27 12 63 41 15 40 58 62 81 6 16 87 32 13 30 79 3 44 58 33 43 45 36 77 84 60 71 46 7 75 70 6 48 0 35 80 13 51 11 5 66 41 85 9 15 28 24 32 74 22 16 55 23 42 40 30 2 83 69 47 8 56 44 82 87 45 22 23 78 72 83 12 30 4 8...
output:
281
result:
ok single line: '281'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3748kb
input:
10 1000 44 82 80 53 70 39 17 60 84 44 26 0 20 42 32 78 33 28 85 56 38 22 4 72 51 47 27 18 79 76 58 12 7 9 52 29 2 19 11 43 15 14 63 83 75 44 22 5 2 77 81 63 34 28 51 48 35 18 44 83 71 73 61 43 68 72 20 3 11 50 74 46 13 9 75 76 26 16 4 27 0 32 56 25 45 49 19 42 59 80 44 78 15 26 42 17 70 58 7 74 61 7...
output:
277
result:
ok single line: '277'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3944kb
input:
10 1000 44 33 47 72 81 60 87 44 4 82 56 45 14 51 69 15 6 75 83 48 76 80 27 64 18 67 23 41 42 40 74 65 24 38 0 63 84 20 66 7 58 2 50 30 12 44 69 29 79 68 86 32 38 82 64 63 62 14 56 70 7 40 42 28 15 21 11 74 87 47 36 60 81 34 27 33 71 30 12 22 26 85 18 58 65 45 83 46 80 59 44 21 29 28 56 66 1 4 15 48 ...
output:
301
result:
ok single line: '301'
Test #5:
score: 0
Accepted
time: 49ms
memory: 16916kb
input:
501 1000 500 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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99...
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 66ms
memory: 16876kb
input:
501 1000 500 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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99...
output:
499
result:
ok single line: '499'