「日常训练」Case of Matryoshkas(Codeforces Round #310 Div. 2 C)

题意与分析(CodeForces 556C)

代码

#include <bits/stdc++.h>
#define MP make_pair
#define PB emplace_back
#define fi first
#define se second
#define ZERO(x) memset((x), 0, sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define rep(i, a, b) for (repType i = (a); i <= (b); ++i)
#define per(i, a, b) for (repType i = (a); i >= (b); --i)
#define QUICKIO                  \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);
using namespace std;
using ll=long long;
using repType=ll;

vector<int> mat[100005];
int main()
{
    int n,k; cin>>n>>k;
    vector<pair<int,int> > vec;
    int cnt=0;
    rep(i,0,k-1)
    {
        int m; cin>>m;
        rep(j,0,m-1)
        {
            int tmp; cin>>tmp;
            mat[i].PB(tmp);
        }
    }
    sort(ALL(vec));
    int cocnt=0,ans=0;
    for(int i=0; i<k; ++i)
    {
        rep(j,1,mat[i].size()-1)
        {
            if(mat[i][j]==j+1) ans++;
            else break;
        }
        
    }
    cout<<(n-1-ans)*2-(k-1)<<endl; // why (n-1-ans) not (n-ans)?
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/samhx/p/CFR310D2C.html