結果
問題 | No.382 シャイな人たち (2) |
ユーザー | Taiki0715 |
提出日時 | 2023-12-31 18:21:26 |
言語 | C++17(clang) (17.0.6 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 3,127 ms / 8,000 ms |
コード長 | 4,227 bytes |
コンパイル時間 | 5,537 ms |
コンパイル使用メモリ | 181,376 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-27 17:09:52 |
合計ジャッジ時間 | 60,195 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3,007 ms
6,816 KB |
testcase_01 | AC | 3,127 ms
6,812 KB |
testcase_02 | AC | 2,604 ms
6,944 KB |
testcase_03 | AC | 2,734 ms
6,940 KB |
testcase_04 | AC | 2,479 ms
6,940 KB |
testcase_05 | AC | 2,834 ms
6,940 KB |
testcase_06 | AC | 2,073 ms
6,940 KB |
testcase_07 | AC | 2,930 ms
6,944 KB |
testcase_08 | AC | 2,177 ms
6,944 KB |
testcase_09 | AC | 2,365 ms
6,940 KB |
testcase_10 | AC | 2,352 ms
6,940 KB |
testcase_11 | AC | 2,117 ms
6,944 KB |
testcase_12 | AC | 2,474 ms
6,940 KB |
testcase_13 | AC | 2,537 ms
6,940 KB |
testcase_14 | AC | 2,864 ms
6,944 KB |
testcase_15 | AC | 2,897 ms
6,940 KB |
testcase_16 | AC | 2,445 ms
6,944 KB |
testcase_17 | AC | 2,265 ms
6,940 KB |
testcase_18 | AC | 2,817 ms
6,940 KB |
testcase_19 | AC | 2,458 ms
6,940 KB |
testcase_20 | AC | 2 ms
6,940 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #if __has_include(<atcoder/all>) #include <atcoder/all> using namespace atcoder; template<int mod>istream &operator>>(istream &is,static_modint<mod> &a){long long b;is>>b;a=b;return is;} istream &operator>>(istream &is,modint &a){long long b;cin>>b;a=b;return is;} #endif #ifdef LOCAL #include "debug.h" #else #define debug(...) static_cast<void>(0) #define debugg(...) static_cast<void>(0) template<typename T1,typename T2>ostream &operator<<(ostream &os,const pair<T1,T2>&p){os<<p.first<<' '<<p.second;return os;} #endif using ll=long long; using ull=unsigned long long; using P=pair<ll,ll>; template<typename T>using minque=priority_queue<T,vector<T>,greater<T>>; template<typename T>bool chmax(T &a,const T &b){return (a<b?(a=b,true):false);} template<typename T>bool chmin(T &a,const T &b){return (a>b?(a=b,true):false);} template<typename T1,typename T2>istream &operator>>(istream &is,pair<T1,T2>&p){is>>p.first>>p.second;return is;} template<typename T>istream &operator>>(istream &is,vector<T> &a){for(auto &i:a)is>>i;return is;} template<typename T1,typename T2>void operator++(pair<T1,T2>&a,int n){a.first++,a.second++;} template<typename T1,typename T2>void operator--(pair<T1,T2>&a,int n){a.first--,a.second--;} template<typename T>void operator++(vector<T>&a,int n){for(auto &i:a)i++;} template<typename T>void operator--(vector<T>&a,int n){for(auto &i:a)i--;} #define reps(i,a,n) for(int i=(a);i<(n);i++) #define rep(i,n) reps(i,0,n) #define all(x) x.begin(),x.end() #define pcnt(x) __builtin_popcount(x) ll myceil(ll a,ll b){return (a+b-1)/b;} template<typename T,size_t n,size_t id=0> auto vec(const int (&d)[n],const T &init=T()){ if constexpr (id<n)return vector(d[id],vec<T,n,id+1>(d,init)); else return init; } void SOLVE(); int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); #ifdef LOCAL clock_t start=clock(); #endif int testcase=1; //cin>>testcase; for(int i=0;i<testcase;i++){ SOLVE(); } #ifdef LOCAL cerr<<"time:"; cerr<<(clock()-start)/1000; cerr<<"ms\n"; #endif } vector<int>MaximumIndependentSet(const vector<vector<bool>>&edge){ int n=edge.size(); vector<int>v(n); iota(all(v),0); vector<int>cnt(n,0); rep(i,n)rep(j,n)cnt[i]+=edge[i][j]; vector<int>ret,now(n); int b=0; auto dfs=[&](auto self,vector<int>::iterator itr,int s){ if(ret.size()>=n+s)return; if(s==0){ if(ret.size()<b)ret=vector<int>(now.begin(),now.begin()+b); return; } int nv=0; rep(i,s)if(cnt[itr[i]]<=1){ swap(itr[0],itr[i]); nv=1; break; } if(nv==0){ rep(i,s)if(cnt[itr[0]]<cnt[itr[i]])swap(itr[0],itr[i]); if(cnt[itr[0]]>=3)nv=2; } if(nv!=0){ int p=itr[0],c=1; reps(i,1,s){ if(edge[p][itr[i]]){ swap(itr[c],itr[i]); reps(j,c+1,s){ cnt[itr[j]]-=edge[itr[c]][itr[j]]; } ++c; } } now[b++]=p; self(self,itr+c,s-c); for(int j=c-1;j>=1;j--)for(int i=j+1;i<s;i++)cnt[itr[i]]+=edge[itr[j]][itr[i]]; b--; if(nv!=1){ rep(i,s)cnt[itr[i]]-=edge[p][itr[i]]; self(self,itr+1,s-1); rep(i,s)cnt[itr[i]]+=edge[p][itr[i]]; } return; } int r=0; vector<bool>seen(s,false); rep(i,s)if(!seen[i]){ for(int u=i,ni=0;!seen[u];ni=1-ni){ int nxt=-1; rep(j,s)if(!seen[j]&&edge[itr[u]][itr[j]]){ nxt=j; break; } if(nxt==-1)break; if(ni)now[b++]=itr[u],r++; seen[u]=true; u=nxt; } } if(ret.size()<b)ret=vector<int>(now.begin(),now.begin()+b); b-=r; }; dfs(dfs,v.begin(),n); return ret; } void SOLVE(){ ll s; cin>>s; s=(s*12345)%1000003; int n=(s%120)+2; s=(s*12345)%1000003; int p=s; vector<vector<int>>f(n,vector<int>(n,0)); rep(i,n)reps(j,i+1,n){ s=(s*12345)%1000003; f[i][j]=f[j][i]=s; } vector<vector<bool>>edge(n,vector<bool>(n,false)); rep(i,n)rep(j,n)edge[i][j]=f[i][j]>=p; auto ans=MaximumIndependentSet(edge); if(ans.size()==n){ cout<<-1<<endl; } else{ cout<<ans.size()+1<<endl; rep(i,ans.size())cout<<ans[i]+1<<" \n"[i+1==ans.size()]; } }