提出 #70440901


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,Q;
string S[3];

array<ll,9> def;
template<class V,int NV> class SegTree_ma {
public:
	vector<V> val;
	V comp(V l,V r){
		int s,t,e;
		array<ll,9> m;
		FOR(s,3) FOR(t,3) m[s*3+t]=1LL<<30;
		FOR(s,3) FOR(t,3) {
			FOR(e,3) chmin(m[s*3+t],l[s*3+e]+r[e*3+t]);
		}
		return m;
	};
	
	SegTree_ma(){val=vector<V>(NV*2,def);};
	void update(int entry, string S) {
		entry += NV;
		int y,x,z;
		FOR(x,3) FOR(y,3) val[entry][x*3+y]=1<<30;
		FOR(x,3) FOR(y,3) {
			int ok=1;
			for(z=min(x,y);z<=max(x,y);z++) if(S[z]=='#') break;
			if(z==max(x,y)+1) chmin(val[entry][x*3+y],abs(x-y)+1LL);
		}
		
		while(entry>1) entry>>=1, val[entry]=comp(val[entry*2],val[entry*2+1]);
	}
};
SegTree_ma<array<ll,9>,1<<20> st;

void solve() {
	int i,j,k,l,r,x,y; string s;
	FOR(x,3) FOR(y,3) def[x*3+y]=(x==y)?0:1<<30;
	FOR(i,1<<21) st.val[i]=def;
	
	cin>>N;
	FOR(y,3) cin>>S[y];
	FOR(i,N) {
		s=S[0][i];
		s+=S[1][i];
		s+=S[2][i];
		st.update(i,s);
	}
	cin>>Q;
	while(Q--) {
		cin>>y>>x;
		y--,x--;
		if(S[y][x]=='#') {
			S[y][x]='.';
		}
		else {
			S[y][x]='#';
		}
		s=S[0][x];
		s+=S[1][x];
		s+=S[2][x];
		st.update(x,s);
		if(st.val[1][2]>=1<<20) {
			cout<<-1<<endl;
		}
		else {
			cout<<st.val[1][2]-1<<endl;
		}
	}
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

提出情報

提出日時
問題 F - Shortest Path Query
ユーザ kmjp
言語 C++ 20 (gcc 12.2)
得点 525
コード長 2108 Byte
結果 AC
実行時間 692 ms
メモリ 151448 KiB

コンパイルエラー

Main.cpp: In function ‘void solve()’:
Main.cpp:50:15: warning: unused variable ‘j’ [-Wunused-variable]
   50 |         int i,j,k,l,r,x,y; string s;
      |               ^
Main.cpp:50:17: warning: unused variable ‘k’ [-Wunused-variable]
   50 |         int i,j,k,l,r,x,y; string s;
      |                 ^
Main.cpp:50:19: warning: unused variable ‘l’ [-Wunused-variable]
   50 |         int i,j,k,l,r,x,y; string s;
      |                   ^
Main.cpp:50:21: warning: unused variable ‘r’ [-Wunused-variable]
   50 |         int i,j,k,l,r,x,y; string s;
      |                     ^
Main.cpp: In function ‘int main(int, char**)’:
Main.cpp:6:19: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
    6 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                   ^~~
Main.cpp:91:9: note: in expansion of macro ‘FOR’
   91 |         FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
      |         ^~~
Main.cpp:6:19: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
    6 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                   ^~~
Main.cpp:91:45: note: in expansion of macro ‘FOR’
   91 |         FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
      |                                             ^~~
Main.cpp:6:28: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
    6 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                            ^
Main.cpp:91:45: note: in expansion of macro ‘FOR’
   91 |         FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
      |                                             ^~~
Main.cpp: In instantiation of ‘void SegTree_ma<V, NV>::update(int, std::string) [with V = std::array<long long int, 9>; int NV = 1048576; std::string = std::__cxx11::basic_string<char>]’:
Main.cpp:60:12:   required from here
Main.cpp:39:29: warning: unused variable ‘ok’ [-Wunused-variable]
   39 |                         int ok=1;
      |                             ^~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 525 / 525
結果
AC × 2
AC × 30
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 67 ms 150504 KiB
00_sample_01.txt AC 68 ms 150596 KiB
01_random_00.txt AC 393 ms 150488 KiB
01_random_01.txt AC 393 ms 150532 KiB
01_random_02.txt AC 391 ms 150680 KiB
01_random_03.txt AC 392 ms 150584 KiB
01_random_04.txt AC 520 ms 150876 KiB
01_random_05.txt AC 486 ms 150968 KiB
01_random_06.txt AC 394 ms 150456 KiB
01_random_07.txt AC 572 ms 151424 KiB
01_random_08.txt AC 458 ms 150528 KiB
01_random_09.txt AC 599 ms 151348 KiB
01_random_10.txt AC 612 ms 151348 KiB
01_random_11.txt AC 619 ms 151348 KiB
01_random_12.txt AC 604 ms 151300 KiB
01_random_13.txt AC 692 ms 151424 KiB
01_random_14.txt AC 617 ms 151436 KiB
01_random_15.txt AC 599 ms 151384 KiB
01_random_16.txt AC 609 ms 151348 KiB
01_random_17.txt AC 608 ms 151404 KiB
01_random_18.txt AC 596 ms 151432 KiB
01_random_19.txt AC 592 ms 151448 KiB
01_random_20.txt AC 592 ms 151424 KiB
01_random_21.txt AC 584 ms 151340 KiB
01_random_22.txt AC 604 ms 151300 KiB
01_random_23.txt AC 602 ms 151352 KiB
01_random_24.txt AC 602 ms 151340 KiB
01_random_25.txt AC 583 ms 151356 KiB
01_random_26.txt AC 582 ms 151296 KiB
01_random_27.txt AC 587 ms 151344 KiB