제출 #1033595

#제출 시각아이디문제언어결과실행 시간메모리
1033595ThanhsTrains (BOI24_trains)C++14
0 / 100
2041 ms612 KiB
// #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();
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:60:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         freopen("in.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:61:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |         freopen("out.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...