結果

問題 No.2288 Somen Sliders
ユーザー 👑 potato167potato167
提出日時 2023-03-14 01:20:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,593 bytes
コンパイル時間 2,539 ms
コンパイル使用メモリ 218,416 KB
実行使用メモリ 13,568 KB
最終ジャッジ日時 2024-04-28 22:53:15
合計ジャッジ時間 9,195 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 WA -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll ILL=2167167167167167167;
const int INF=2100000000;
const int mod=998244353;
#define rep(i,a,b) for (int i=a;i<b;i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}
template<class T> void vec_out(vector<T> &p){for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}
template<class T> T vec_min(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;}
template<class T> T vec_max(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;}
template<class T> T vec_sum(vector<T> &a){assert(!a.empty());T ans=a[0]-a[0];for(auto &x:a) ans+=x;return ans;}



void solve();
// oddloop
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t=1;
	//cin>>t;
	rep(i,0,t) solve();
}

void solve(){
	int N,X,Y;
	cin>>N>>X>>Y;
	vector<vector<int>> P(X);
	vector<vector<int>> Q(Y);
	rep(i,0,X){
		int k;
		cin>>k;
		rep(j,0,k+1){
			int a;cin>>a;P[i].push_back(a-1);
		}
	}
	rep(i,0,Y){
		int l;
		cin>>l;
		rep(j,0,l+1){
			int a;cin>>a;Q[i].push_back(a-1);
		}
		reverse(all(Q[i]));
	}
	vector<pair<int,int>> W(N,{-1,-1});
	rep(i,0,X){
		rep(j,0,(int)(P[i].size())){
			W[P[i][j]]={i,j};
		}
	}
	set<int> rem;
	rep(i,0,Y) rem.insert(i);
	vector<pair<int,int>> ops(X,{-1,-1});
	vector<int> pos(Y);
	while(!rem.empty()){
		int a=(*rem.begin());
		rem.erase(a);
		while(pos[a]!=(int)(Q[a].size())){
			if(W[Q[a][pos[a]]].first!=-1){
				int p,w;
				tie(p,w)=W[Q[a][pos[a]]];
				if(ops[p].first==-1||
				ops[p].second>w){
					if(ops[p].first!=-1){
						int tmp=ops[p].first;
						rem.insert(tmp);
						pos[tmp]++;
					}
					ops[p]={a,w};
					break;
				}
			}
			pos[a]++;
		}
	}
	int ans=0;
	rep(i,0,X){
		if(ops[i].first==-1) ans+=(int)(P[i].size())-1;
		else ans+=ops[i].second;
	}
	cout<<ans<<"\n";
}

0