結果

問題 No.1401 全自動マクロの作り方
ユーザー chocoruskchocorusk
提出日時 2021-02-24 09:39:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 3,153 ms
コード長 1,390 bytes
コンパイル時間 1,337 ms
コンパイル使用メモリ 133,672 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 17:12:07
合計ジャッジ時間 11,923 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/vector:64,
                 from main.cpp:7:
In member function 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>]',
    inlined from 'int main()' at main.cpp:41:23:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_vector.h:1283:13: warning: 'a' may be used uninitialized [-Wmaybe-uninitialized]
 1283 |             ++this->_M_impl._M_finish;
      |             ^~
main.cpp: In function 'int main()':
main.cpp:34:13: note: 'a' was declared here
   34 |         int a, b;
      |             ^

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <stack>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int n; cin>>n;
    vector<int> g[2020];
    int deg[2020]={};
    for(int i=0; i<n; i++){
        int d; cin>>d;
        int a, b;
        for(int j=0; j<d; j++){
            int s; cin>>s;
            if(j==0) a=s;
            if(j==d-1) b=s;
        }
        if(a==b) continue;
        g[a].push_back(b);
        deg[b]++;
    }
    const int N=2000;
    queue<int> que;
    for(int i=0; i<N; i++){
        if(deg[i]==0) que.push(i);
    }
    vector<int> ans;
    while(!que.empty()){
        int x=que.front(); que.pop();
        ans.push_back(x);
        for(auto y:g[x]){
            deg[y]--;
            if(deg[y]==0) que.push(y);
        }
    }
    if(ans.size()<N) cout<<0<<endl;
    else{
        cout<<N<<endl;
        for(int i=0; i<N; i++){
            cout<<ans[i];
            if(i<N-1) cout<<" ";
        }
        cout<<endl;
    }
    return 0;
}
0