Submission #71950671


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=2e5+10,inf=1e18;
ll n,m,x,y;
string s[3];
struct Mat{
	ll a[3][3]={};
	void init(){
		for(int i=0;i<3;i++)
			for(int j=0;j<3;j++) a[i][j]=inf;
	}
	void init2(ll x){
		for(int i=0;i<3;i++)
			for(int j=0;j<3;j++){
				bool ok=1;
				for(int k=min(i,j);k<=max(i,j);k++)
					if(s[k][x]=='#'){a[i][j]=inf;ok=0;break;}
				if(ok) a[i][j]=abs(j-i);
			}
	}
	ll *operator[](int x){return a[x];}
	Mat operator*(Mat b){
		Mat c;c.init();
		for(int i=0;i<3;i++)
			for(int k=0;k<3;k++)
				for(int j=0;j<3;j++)
					c[i][j]=min(c[i][j],a[i][k]+b[k][j]+1);
		return c;
	}
}t[N<<2];
#define mid (l+r>>1)
#define ls (rt<<1)
#define rs (ls|1)
#define L ls,l,mid
#define R rs,mid+1,r
void up(ll rt){t[rt]=t[ls]*t[rs];}
void build(ll rt,ll l,ll r){
	if(l==r){t[rt].init2(l);return;}
	build(L),build(R),up(rt);
}
void upd(ll rt,ll l,ll r,ll x,ll y){
	if(l>y||y>r) return;
	if(l==r){s[x][y]=(s[x][y]=='#'?'.':'#');t[rt].init2(l);return;}
	upd(L,x,y),upd(R,x,y),up(rt);
}
int main()
{
	ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=0;i<3;i++) cin>>s[i];
	build(1,0,n-1);
	cin>>m;
	while(m--){
		cin>>x>>y;x--,y--;
		upd(1,0,n-1,x,y);
		ll ans=t[1][0][2];
		cout<<(ans<inf?ans:-1)<<"\n";
	}
	return 0;
}

Submission Info

Submission Time
Task F - Shortest Path Query
User jianhe
Language C++23 (GCC 15.2.0)
Score 525
Code Size 1350 Byte
Status AC
Exec Time 223 ms
Memory 40968 KiB

Compile Error

./Main.cpp: In function 'void build(long long int, long long int, long long int)':
./Main.cpp:32:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   32 | #define mid (l+r>>1)
      |              ~^~
./Main.cpp:35:16: note: in expansion of macro 'mid'
   35 | #define L ls,l,mid
      |                ^~~
./Main.cpp:40:15: note: in expansion of macro 'L'
   40 |         build(L),build(R),up(rt);
      |               ^
./Main.cpp:32:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   32 | #define mid (l+r>>1)
      |              ~^~
./Main.cpp:36:14: note: in expansion of macro 'mid'
   36 | #define R rs,mid+1,r
      |              ^~~
./Main.cpp:40:24: note: in expansion of macro 'R'
   40 |         build(L),build(R),up(rt);
      |                        ^
./Main.cpp: In function 'void upd(long long int, long long int, long long int, long long int, long long int)':
./Main.cpp:32:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   32 | #define mid (l+r>>1)
      |              ~^~
./Main.cpp:35:16: note: in expansion of macro 'mid'
   35 | #define L ls,l,mid
      |                ^~~
./Main.cpp:45:13: note: in expansion of macro 'L'
   45 |         upd(L,x,y),upd(R,x,y),up(rt);
      |             ^
./Main.cpp:32:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   32 | #define mid (l+r>>1)
      |              ~^~
./Main.cpp:36:14: note: in expansion of macro 'mid'
   36 | #define R rs,mid+1,r
      |              ^~~
./Main.cpp:45:24: note: in expansion of macro 'R'
   45 |         upd(L,x,y),upd(R,x,y),up(rt);
      |                        ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 525 / 525
Status
AC × 2
AC × 30
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3536 KiB
00_sample_01.txt AC 1 ms 3588 KiB
01_random_00.txt AC 31 ms 3536 KiB
01_random_01.txt AC 32 ms 3472 KiB
01_random_02.txt AC 31 ms 3632 KiB
01_random_03.txt AC 31 ms 3408 KiB
01_random_04.txt AC 177 ms 22216 KiB
01_random_05.txt AC 161 ms 12932 KiB
01_random_06.txt AC 111 ms 4176 KiB
01_random_07.txt AC 200 ms 40720 KiB
01_random_08.txt AC 147 ms 12884 KiB
01_random_09.txt AC 216 ms 40736 KiB
01_random_10.txt AC 210 ms 40808 KiB
01_random_11.txt AC 210 ms 40968 KiB
01_random_12.txt AC 212 ms 40812 KiB
01_random_13.txt AC 209 ms 40904 KiB
01_random_14.txt AC 213 ms 40812 KiB
01_random_15.txt AC 211 ms 40872 KiB
01_random_16.txt AC 207 ms 40848 KiB
01_random_17.txt AC 210 ms 40964 KiB
01_random_18.txt AC 217 ms 40860 KiB
01_random_19.txt AC 214 ms 40812 KiB
01_random_20.txt AC 212 ms 40848 KiB
01_random_21.txt AC 221 ms 40832 KiB
01_random_22.txt AC 223 ms 40812 KiB
01_random_23.txt AC 220 ms 40860 KiB
01_random_24.txt AC 215 ms 40856 KiB
01_random_25.txt AC 211 ms 40848 KiB
01_random_26.txt AC 210 ms 40908 KiB
01_random_27.txt AC 208 ms 40864 KiB