답안 #540613

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
540613 2022-03-21T08:15:41 Z idas Fire drill (LMIO18_sauga) C++11
26.2973 / 100
1000 ms 5268 KB
#include <bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr)
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define TSTS int ttt; cin >> ttt; while(ttt--) solve()
#define all(x) (x).begin(), (x).end()
#define le(vec) vec[vec.size()-1]
#define sz(x) ((int)((x).size()))
#define pb push_back
#define s second
#define f first

using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pdd;

const int INF=1e9, MOD=1e9+7, mod=998244353;
const ll LINF=1e18;

void setIO()
{
    FAST_IO;
}

void setIO(string s)
{
    FAST_IO;
    freopen((s+".in").c_str(), "r", stdin);
    freopen((s+".out").c_str(), "w", stdout);
}

const int N=1e3+10;
int t, n, s, cn[N];
bool v[N], off[N];
vi ad[N];

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void dfs(int u)
{
    v[u]=true;
    for(auto x : ad[u]){
        cn[x]++;
        if(!v[x] && !off[x]){
            dfs(x);
        }
    }
}

int main()
{
    setIO();
    cin >> t >> n >> s;
    FOR(i, 0, n)
    {
        int x; cin >> x;
        FOR(j, 0, x)
        {
            int b; cin >> b;
            b--; ad[i].pb(b);
        }
    }

    vi left;
    FOR(i, 0, n) left.pb(i);
    shuffle(all(left), rng);

    FOR(i, 0, n)
    {
        FOR(j, 0, n) v[j]=false, cn[j]=0;

        int num=rng()%(sz(left)), in=left[num];
        dfs(in);

        int mx=-1, mxin=-1;
        FOR(j, 0, n)
        {
            if(off[j]) continue;
            if(cn[j]>mx){
                mx=cn[j];
                mxin=j;
            }
        }
        off[mxin]=true;
        cout << mxin+1 << '\n';

        if(in==-1) break;

        vi nw;
        FOR(j, 0, n) if(!off[j]) nw.pb(j);
        left=nw;
    }
}

Compilation message

sauga.cpp: In function 'void setIO(std::string)':
sauga.cpp:32:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     freopen((s+".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sauga.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     freopen((s+".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 404 ms 5268 KB Output is partially correct
2 Partially correct 10 ms 364 KB Output is partially correct
3 Partially correct 14 ms 440 KB Output is partially correct
4 Partially correct 25 ms 340 KB Output is partially correct
5 Partially correct 19 ms 340 KB Output is partially correct
6 Partially correct 26 ms 468 KB Output is partially correct
7 Partially correct 73 ms 1104 KB Output is partially correct
8 Execution timed out 1083 ms 4812 KB Time limit exceeded
9 Partially correct 22 ms 732 KB Output is partially correct
10 Partially correct 7 ms 444 KB Output is partially correct