# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1033595 | Thanhs | Trains (BOI24_trains) | C++14 | 2041 ms | 612 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
// #define int long long
// #define double long double
#define endl '\n'
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define setmin(x, y) x = min((x), (y))
#define setmax(x, y) x = max((x), (y))
#define sqr(x) ((x) * (x))
#define fi first
#define se second
#define all(x) x.begin(), x.end()
// mt19937 hdp(chrono::high_resolution_clock::now().time_since_epoch().count());
// int rand(int l, int r){return l + ((hdp() % (r - l + 1)) + r - l + 1) % (r - l + 1);}
const int NM = 5e2 + 5;
const int mod = 1e9 + 7;
int n, ans, p, d[NM][NM], b[NM], c[NM];
void sub1()
{
for (int i = 1; i <= n; i++)
ans += (d[i][1] == i);
cout << ans << endl;
for (int i = 1; i <= n; i++)
if (d[i][1] == i)
cout << i << ' ';
}
void sub2()
{
for (int i = 1; i <= n; i++)
b[d[i][1]] = 1;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
{
c[d[i][j]] = 1;
if (d[i][j] == i || b[d[i][j]])
break;
cout << d[i][j] << endl;
}
for (int i = 1; i <= n; i++)
c[i] |= b[i];
cout << accumulate(c + 1, c + 1 + n, 0) << endl;
for (int i = 1; i <= n; i++)
if (c[i])
cout << i << ' ';
}
signed main()
{
fastIO
if (fopen("in.txt", "r"))
{
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
}
cin >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
cin >> d[i][j];
cin >> p;
if (p == 1)
sub1();
else
sub2();
}
Compilation message (stderr)
# | 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... |