頭良くなりたい人

文系大学生shadeのブログです。競技プログラミングや人文学の話題,受験ネタなど。

ABC118 B - Foods Loved by Everyone

問題はこちら atcoder.jp

方針

ゴリゴリ調べる。

コード

#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n,m;
    cin>>n>>m;
 
    vector<int> k(n);
    vector<vector<int>> a(n, vector<int>(m));
    for(int i=0; i<n; i++){
        cin>>k[i];
        for(int j=0; j<k[i]; j++){
            cin>>a[i][j];
        }
    }
 
    bool check=false;
    int count=0,loved=0;
 
    for(int i=1; i<=m; i++){
        for(int j=0; j<n; j++){
            int k=0;
            while(check==false && k<m){
                if(a[j][k]==i){
                    check=true;
                }
                k++;
            }
            if(check==true){
                count++;
            }
            check=false;
        }
        if(count==n){
            loved++;
        }
        count=0;
    }
 
    cout<<loved<<endl;
}