CodeForces-1798#B 题解
正文
开个数组
将
因为本题是 SPJ,对于每个桶 vector
,每个桶只需要存一个元素,用 C++ 内置数组完全够用。
因为懒,我将 unordered_map
取代。
#include<iostream> #include<cstring> #include<unordered_map> using namespace std; const int N=5e4+7; int t,m,n,a,day[N]; unordered_map<int,int> last; int main(){ ios::sync_with_stdio(false),cin.tie(0); cin>>t; while(t--){ last.clear(); memset(day,0,sizeof day); cin>>m; for(int i=1;i<=m;i++){ cin>>n; for(int j=1;j<=n;j++) cin>>a,last[a]=i; } int M=m;//统计还有多少桶是空的 for(auto &i: last){//将last放入桶中 if(!day[i.second]) M--; day[i.second]=i.first; } if(M) cout<<-1; else for(int i=1;i<=m;i++) cout<<day[i]<<' '; cout<<'\n'; } }
后附
日志
v1.0 on 2023.08.14: 发布
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步