結果
問題 | No.1266 7 Colors |
ユーザー | hamamu |
提出日時 | 2020-10-23 23:01:46 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 162 ms / 3,000 ms |
コード長 | 6,881 bytes |
コンパイル時間 | 2,619 ms |
コンパイル使用メモリ | 212,452 KB |
実行使用メモリ | 30,464 KB |
最終ジャッジ日時 | 2024-07-21 12:11:58 |
合計ジャッジ時間 | 6,423 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 81 ms
9,964 KB |
testcase_04 | AC | 141 ms
22,484 KB |
testcase_05 | AC | 87 ms
10,624 KB |
testcase_06 | AC | 150 ms
24,420 KB |
testcase_07 | AC | 162 ms
27,376 KB |
testcase_08 | AC | 139 ms
22,888 KB |
testcase_09 | AC | 126 ms
18,488 KB |
testcase_10 | AC | 117 ms
16,944 KB |
testcase_11 | AC | 98 ms
12,160 KB |
testcase_12 | AC | 105 ms
13,664 KB |
testcase_13 | AC | 110 ms
15,104 KB |
testcase_14 | AC | 86 ms
10,528 KB |
testcase_15 | AC | 159 ms
27,736 KB |
testcase_16 | AC | 111 ms
14,080 KB |
testcase_17 | AC | 161 ms
26,604 KB |
testcase_18 | AC | 74 ms
30,464 KB |
testcase_19 | AC | 75 ms
28,208 KB |
testcase_20 | AC | 75 ms
28,236 KB |
testcase_21 | AC | 40 ms
6,940 KB |
ソースコード
#include "bits/stdc++.h" using namespace std; using ll=long long; using vll=vector< ll>; using vvll=vector< vll>; using vvvll=vector< vvll>; using vvvvll=vector<vvvll>; using dd=double; using vdd=vector< dd>; using vvdd=vector< vdd>; using pll=pair<ll,ll>; using tll=tuple<ll,ll,ll>; using qll=tuple<ll,ll,ll,ll>; using vpll=vector< pll>; constexpr ll INF = 1LL << 60; struct Fast{ Fast(){ cin.tie(0); ios::sync_with_stdio(false); cout<<fixed<<setprecision(numeric_limits<double>::max_digits10); } } fast; #define REPS(i, S, E) for (ll i = (S); i <= (E); i++) #define REP(i, N) REPS(i, 0, (N)-1) #define DEPS(i, S, E) for (ll i = (E); i >= (S); i--) #define DEP(i, N) DEPS(i, 0, (N)-1) #define rep(i, S, E) for (ll i = (S); i <= (E); i++) #define dep(i, E, S) for (ll i = (E); i >= (S); i--) #define each(e, v) for (auto&& e : v) #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; }return false; } template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; }return false; } template<class T> inline T MaxE(vector<T>&v,ll S,ll E){ T m=v[S]; rep(i,S,E)chmax(m,v[i]); return m; } template<class T> inline T MinE(vector<T>&v,ll S,ll E){ T m=v[S]; rep(i,S,E)chmin(m,v[i]); return m; } template<class T> inline T MaxE(vector<T> &v) { return MaxE(v,0,(ll)v.size()-1); } template<class T> inline T MinE(vector<T> &v) { return MinE(v,0,(ll)v.size()-1); } template<class T> inline T Sum(vector<T> &v,ll S,ll E){ T s=T(); rep(i,S,E)s+=v[i]; return s; } template<class T> inline T Sum(vector<T> &v) { return Sum(v,0,v.size()-1); } template<class T> inline ll sz(T &v){ return (ll)v.size(); } inline ll CEIL(ll a,ll b){ return (a<0) ? -(-a/b) : (a+b-1)/b; } inline ll FLOOR(ll a,ll b){ return -CEIL(-a,b); } #if 0 #include <atcoder/all> using namespace atcoder; #endif //tuple3用テンプレート using vtll=vector< tll>; using vvtll=vector<vtll>; template<class T,class S,class R> inline tuple<T,S,R>& operator+=(tuple<T,S,R> &a,const tuple<T,S,R> &b){ get<0>(a)+=get<0>(b); get<1>(a)+=get<1>(b); get<2>(a)+=get<2>(b); return a; } template<class T,class S,class R> inline tuple<T,S,R>& operator-=(tuple<T,S,R> &a,const tuple<T,S,R> &b){ get<0>(a)-=get<0>(b); get<1>(a)-=get<1>(b); get<2>(a)-=get<2>(b); return a; } template<class T,class S,class R> inline tuple<T,S,R>& operator*=(tuple<T,S,R> &a,const tuple<T,S,R> &b){ get<0>(a)*=get<0>(b); get<1>(a)*=get<1>(b); get<2>(a)*=get<2>(b); return a; } template<class T,class S,class R> inline tuple<T,S,R>& operator/=(tuple<T,S,R> &a,const tuple<T,S,R> &b){ get<0>(a)/=get<0>(b); get<1>(a)/=get<1>(b); get<2>(a)/=get<2>(b); return a; } template<class T,class S,class R> inline tuple<T,S,R>& operator%=(tuple<T,S,R> &a,const tuple<T,S,R> &b){ get<0>(a)%=get<0>(b); get<1>(a)%=get<1>(b); get<2>(a)%=get<2>(b); return a; } template<class T,class S,class R,class Q> inline tuple<T,S,R>& operator+=(tuple<T,S,R> &a,Q b){ get<0>(a)+=b; get<1>(a)+=b; get<2>(a)+=b; return a; } template<class T,class S,class R,class Q> inline tuple<T,S,R>& operator-=(tuple<T,S,R> &a,Q b){ get<0>(a)-=b; get<1>(a)-=b; get<2>(a)-=b; return a; } template<class T,class S,class R,class Q> inline tuple<T,S,R>& operator*=(tuple<T,S,R> &a,Q b){ get<0>(a)*=b; get<1>(a)*=b; get<2>(a)*=b; return a; } template<class T,class S,class R,class Q> inline tuple<T,S,R>& operator/=(tuple<T,S,R> &a,Q b){ get<0>(a)/=b; get<1>(a)/=b; get<2>(a)/=b; return a; } template<class T,class S,class R,class Q> inline tuple<T,S,R>& operator%=(tuple<T,S,R> &a,Q b){ get<0>(a)%=b; get<1>(a)%=b; get<2>(a)%=b; return a; } template<class T,class S,class R,class Q> inline tuple<T,S,R> operator+(const tuple<T,S,R> &a,Q b){ tuple<T,S,R> c=a; return c+=b; } template<class T,class S,class R,class Q> inline tuple<T,S,R> operator-(const tuple<T,S,R> &a,Q b){ tuple<T,S,R> c=a; return c-=b; } template<class T,class S,class R,class Q> inline tuple<T,S,R> operator*(const tuple<T,S,R> &a,Q b){ tuple<T,S,R> c=a; return c*=b; } template<class T,class S,class R,class Q> inline tuple<T,S,R> operator/(const tuple<T,S,R> &a,Q b){ tuple<T,S,R> c=a; return c/=b; } template<class T,class S,class R,class Q> inline tuple<T,S,R> operator%(const tuple<T,S,R> &a,Q b){ tuple<T,S,R> c=a; return c%=b; } template<class T,class S,class R,class Q> inline tuple<T,S,R> operator-(Q b,const tuple<T,S,R> &a){ tuple<T,S,R> c=-a; return c+=b; } template<class T,class S,class R> inline tuple<T,S,R> operator-(const tuple<T,S,R> &a){ tuple<T,S,R> c=a; return c*=(-1); } template<class T,class S,class R> inline ostream &operator<<(ostream &os,const tuple<T,S,R> &a){ return os << get<0>(a) << ' ' << get<1>(a) << ' ' << get<2>(a); } vvll cinGraph(ll nodeNum,ll edgeNum,bool isDirected){//無向false、有向true vvll to(nodeNum); rep(i,0,edgeNum-1){ ll v,u; cin >> v >> u; v--; u--; to[v].push_back(u); if (!isDirected) to[u].push_back(v); } return move(to); } class UnionFindTree{ private: vll par,rank,size; public: UnionFindTree(ll num): par(num),rank(num),size(num,1){ rep(i,0,num-1) par[i] = i; } bool Same(ll x,ll y) { return Root(x) == Root(y); } ll Root(ll x) { return (par[x] == x) ? x : par[x]=Root(par[x]); } ll Size(ll x){ return size[Root(x)]; } void Unite(ll x,ll y){ x = Root(x); y = Root(y); if (x == y) return; if (rank[x] < rank[y]) par[x] = y; else par[y] = x; if (rank[x] == rank[y]) rank[x]++; size[x] = size[y] = size[x] + size[y]; } }; /* UnionFindTree uft(N); uft.Unite(x,y); bool b = uft.Same(x,y); ll num = uft.Size(x); ll v = uft.Root(x); */ void solve() { ll M=7; ll n,m,q; cin >> n >> m >> q; vector<string> s(n); rep(i,0,n-1){ string s_; cin>>s_; s[i]=s_; } vvll to = cinGraph(n,m,false); //vector<pair<ll,ll>> uv(m); //rep(i,0,m-1){ ll u; ll v; cin>>u>>v; uv[i]={u,v}; } UnionFindTree uft(n*M); //M*v+c rep(v,0,n-1){ each(u,to[v]){ if (u<v)continue; rep(c,0,M-1){ if (s[u][c]=='1' and s[v][c]=='1'){ uft.Unite(M*v+c,M*u+c); } } } rep(c,0,M-1){ if (s[v][c]=='1' and s[v][(c+1)%M]=='1'){ uft.Unite(M*v+c,M*v+(c+1)%M); } } } vll ans; rep(qq,0,q-1){ ll kind,v,c; cin >> kind >> v >> c; v--; c--; if (kind==1){ s[v][c]='1'; each(u,to[v]){ if (s[u][c]=='1'){ uft.Unite(M*v+c,M*u+c); } } if (s[v][(c+1)%M]=='1'){ uft.Unite(M*v+c,M*v+(c+1)%M); } if (s[v][(c+M-1)%M]=='1'){ uft.Unite(M*v+c,M*v+(c+M-1)%M); } } else{ ans.push_back(uft.Size(M*v)); } } each(e,ans) cout << e << '\n'; } int main(){ #if 1 solve(); #else ll t; cin >> t; rep(i, 0, t-1){ solve(); } #endif return 0; }