結果
問題 | No.2288 Somen Sliders |
ユーザー |
![]() |
提出日時 | 2023-04-27 23:00:27 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 305 ms / 2,000 ms |
コード長 | 1,083 bytes |
コンパイル時間 | 2,230 ms |
コンパイル使用メモリ | 203,092 KB |
最終ジャッジ日時 | 2025-02-12 14:31:21 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0;i<(n);i++) int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n,x,y;cin>>n>>x>>y; constexpr pair<int,int> null{-1,-1}; vector<pair<int,int>> P(n,null); vector<pair<int,int>> match(x); vector<stack<int>> Q(y); REP(i1,x){ int k;cin>>k; match[i1]={-1,k}; REP(j1,k+1){ int u;cin>>u;u--; if(clamp(u,0,n-1)!=u)continue; P[u]={i1,j1}; } } REP(i2,y){ int l;cin>>l; REP(j2,l+1){ int v;cin>>v;v--; if(clamp(v,0,n-1)!=v or P[v]==null)continue; Q[i2].push(v); } } queue<int> que; REP(i2,y)que.push(i2); while(que.size()){ int i2=que.front();que.pop(); cerr<<i2<<'\n'; while(Q[i2].size()){ int v=Q[i2].top();Q[i2].pop(); auto [i1,j1]=P[v]; if(match[i1].second > j1){ if(~match[i1].first) que.push(match[i1].first); match[i1] = {i2, j1}; break; } } } int ans=0; for(const auto&[_,score]:match)ans+=score; cout<<ans<<'\n'; }