結果

問題 No.1266 7 Colors
ユーザー たたき@競プロたたき@競プロ
提出日時 2023-09-09 11:54:19
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 304 ms / 3,000 ms
コード長 1,096 bytes
コンパイル時間 6,579 ms
コンパイル使用メモリ 309,432 KB
実行使用メモリ 14,812 KB
最終ジャッジ日時 2023-09-09 11:54:34
合計ジャッジ時間 14,301 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,356 KB
testcase_02 AC 2 ms
4,356 KB
testcase_03 AC 238 ms
5,720 KB
testcase_04 AC 304 ms
10,944 KB
testcase_05 AC 237 ms
6,176 KB
testcase_06 AC 278 ms
11,928 KB
testcase_07 AC 285 ms
13,116 KB
testcase_08 AC 296 ms
11,192 KB
testcase_09 AC 261 ms
9,504 KB
testcase_10 AC 256 ms
8,856 KB
testcase_11 AC 241 ms
6,784 KB
testcase_12 AC 257 ms
7,512 KB
testcase_13 AC 253 ms
8,128 KB
testcase_14 AC 241 ms
6,044 KB
testcase_15 AC 290 ms
13,372 KB
testcase_16 AC 262 ms
7,616 KB
testcase_17 AC 282 ms
12,888 KB
testcase_18 AC 278 ms
14,812 KB
testcase_19 AC 158 ms
14,308 KB
testcase_20 AC 157 ms
14,312 KB
testcase_21 AC 222 ms
4,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using mint=modint998244353; //1000000007;
using ll=long long;
using pp=pair<ll,ll>;
#define sr string 
#define vc vector
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define pque priority_queue
#define bpc(a) __builtin_popcount(a)
int main(){
  int n,m,q;cin>>n>>m>>q;
  vc<sr>s(n); rep(i,n)cin>>s[i];
  dsu d(n*7);
  vc v(n,vc<int>(0));
  rep(i,m){
    int a,b;cin>>a>>b; a--;b--;
    v[a].pb(b);v[b].pb(a);
    rep(j,7)if(s[a][j]=='1'&&s[b][j]=='1')d.merge(7*a+j,7*b+j);
  }
  rep(i,n)rep(j,7){
    int nj=(j+1)%7;
    if(s[i][j]=='1'&&s[i][nj]=='1')d.merge(i*7+j,i*7+nj);
  }
  rep(z,q){
    int t,x,y;cin>>t>>x>>y; x--; y--;
    if(t==1){
      s[x][y]='1';
      int ny=(y+1)%7;
      if(s[x][ny]=='1')d.merge(7*x+y,7*x+ny);
      ny=(y-1+7)%7; 
      if(s[x][ny]=='1')d.merge(7*x+y,7*x+ny);
      for(auto au:v[x])if(s[au][y]=='1')d.merge(7*x+y,7*au+y);
    }
    else{
      cout<<d.size(x*7)<<"\n";
    }
  }
}
0