Submission #15445374


Source Code Expand

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

#undef _P
#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 ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int X[202020],Y[202020];
string U[202020];

vector<pair<int,int>> LR[402020],UD[402020],RU[402020],LD[402020],LU[402020],RD[402020];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	int ret=1<<30;
	cin>>N;
	FOR(i,N) {
		cin>>X[i]>>Y[i]>>U[i];
		
		if(U[i]=="L" || U[i]=="R") LR[Y[i]].push_back({X[i],i});
		if(U[i]=="U" || U[i]=="D") UD[X[i]].push_back({Y[i],i});
		if(U[i]=="L" || U[i]=="D") LD[X[i]+Y[i]].push_back({Y[i],i});
		if(U[i]=="R" || U[i]=="U") RU[X[i]+Y[i]].push_back({Y[i],i});
		if(U[i]=="L" || U[i]=="U") LU[Y[i]-X[i]+200000].push_back({X[i],i});
		if(U[i]=="R" || U[i]=="D") RD[Y[i]-X[i]+200000].push_back({X[i],i});
		
	}
	
	FOR(i,400001) {
		sort(ALL(LR[i]));
		sort(ALL(UD[i]));
		sort(ALL(LD[i]));
		sort(ALL(RU[i]));
		sort(ALL(LU[i]));
		sort(ALL(RD[i]));
		FOR(j,(int)LR[i].size()-1) if(U[LR[i][j].second]=="R"&&U[LR[i][j+1].second]=="L") ret=min(ret,(LR[i][j+1].first-LR[i][j].first)*5);
		FOR(j,(int)UD[i].size()-1) if(U[UD[i][j].second]=="U"&&U[UD[i][j+1].second]=="D") ret=min(ret,(UD[i][j+1].first-UD[i][j].first)*5);
		FOR(j,(int)LD[i].size()-1) if(U[LD[i][j].second]=="L"&&U[LD[i][j+1].second]=="D") ret=min(ret,(LD[i][j+1].first-LD[i][j].first)*10);
		FOR(j,(int)RU[i].size()-1) if(U[RU[i][j].second]=="U"&&U[RU[i][j+1].second]=="R") ret=min(ret,(RU[i][j+1].first-RU[i][j].first)*10);
		FOR(j,(int)LU[i].size()-1) if(U[LU[i][j].second]=="U"&&U[LU[i][j+1].second]=="L") ret=min(ret,(LU[i][j+1].first-LU[i][j].first)*10);
		FOR(j,(int)RD[i].size()-1) if(U[RD[i][j].second]=="R"&&U[RD[i][j+1].second]=="D") ret=min(ret,(RD[i][j+1].first-RD[i][j].first)*10);
		
	}
	
	
	
	if(ret==1<<30) {
		cout<<"SAFE"<<endl;
	}
	else {
		cout<<ret<<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;
}

Submission Info

Submission Time
Task F - Air Safety
User kmjp
Language C++ (GCC 9.2.1)
Score 600
Code Size 2423 Byte
Status AC
Exec Time 291 ms
Memory 86416 KB

Compile Error

./Main.cpp: In function ‘void solve()’:
./Main.cpp:22:10: warning: unused variable ‘k’ [-Wunused-variable]
   22 |  int i,j,k,l,r,x,y; string s;
      |          ^
./Main.cpp:22:12: warning: unused variable ‘l’ [-Wunused-variable]
   22 |  int i,j,k,l,r,x,y; string s;
      |            ^
./Main.cpp:22:14: warning: unused variable ‘r’ [-Wunused-variable]
   22 |  int i,j,k,l,r,x,y; string s;
      |              ^
./Main.cpp:22:16: warning: unused variable ‘x’ [-Wunused-variable]
   22 |  int i,j,k,l,r,x,y; string s;
      |                ^
./Main.cpp:22:18: warning: unused variable ‘y’ [-Wunused-variable]
   22 |  int i,j,k,l,r,x,y; string s;
      |                  ^
./Main.cpp: In function ‘int main(int, char**)’:
./Main.cpp:7:28: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
    7 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                            ^
./Main.cpp:68:38: note: in expansion of macro ‘FOR’
   68 |  FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
      |                                      ^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 57
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in30.txt, in31.txt, in32.txt, in33.txt, in34.txt, in35.txt, in36.txt, in37.txt, in38.txt, in39.txt, in40.txt, in41.txt, in42.txt, in43.txt, in44.txt, in45.txt, in46.txt, in47.txt, in48.txt, in49.txt, in50.txt, in51.txt, in52.txt, in53.txt, in54.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
in01.txt AC 62 ms 66324 KB
in02.txt AC 63 ms 66372 KB
in03.txt AC 64 ms 66388 KB
in04.txt AC 64 ms 66500 KB
in05.txt AC 68 ms 67008 KB
in06.txt AC 83 ms 68456 KB
in07.txt AC 102 ms 70472 KB
in08.txt AC 151 ms 74264 KB
in09.txt AC 291 ms 83688 KB
in10.txt AC 170 ms 75084 KB
in11.txt AC 60 ms 66348 KB
in12.txt AC 59 ms 66528 KB
in13.txt AC 74 ms 67908 KB
in14.txt AC 223 ms 77256 KB
in15.txt AC 60 ms 66372 KB
in16.txt AC 220 ms 78428 KB
in17.txt AC 52 ms 66356 KB
in18.txt AC 59 ms 66488 KB
in19.txt AC 82 ms 68036 KB
in20.txt AC 225 ms 78784 KB
in21.txt AC 60 ms 66360 KB
in22.txt AC 60 ms 66540 KB
in23.txt AC 82 ms 68040 KB
in24.txt AC 233 ms 79208 KB
in25.txt AC 59 ms 66304 KB
in26.txt AC 266 ms 81348 KB
in27.txt AC 63 ms 66320 KB
in28.txt AC 233 ms 83520 KB
in29.txt AC 61 ms 66372 KB
in30.txt AC 272 ms 81764 KB
in31.txt AC 57 ms 66360 KB
in32.txt AC 136 ms 80492 KB
in33.txt AC 62 ms 66300 KB
in34.txt AC 136 ms 79860 KB
in35.txt AC 60 ms 66396 KB
in36.txt AC 137 ms 81112 KB
in37.txt AC 55 ms 66320 KB
in38.txt AC 134 ms 77156 KB
in39.txt AC 64 ms 66312 KB
in40.txt AC 137 ms 81300 KB
in41.txt AC 147 ms 83332 KB
in42.txt AC 142 ms 74888 KB
in43.txt AC 146 ms 73924 KB
in44.txt AC 143 ms 86416 KB
in45.txt AC 142 ms 75068 KB
in46.txt AC 141 ms 81320 KB
in47.txt AC 141 ms 81396 KB
in48.txt AC 140 ms 77244 KB
in49.txt AC 58 ms 66372 KB
in50.txt AC 65 ms 66320 KB
in51.txt AC 60 ms 66396 KB
in52.txt AC 64 ms 66416 KB
in53.txt AC 66 ms 66392 KB
in54.txt AC 62 ms 66372 KB
sample_01.txt AC 65 ms 66312 KB
sample_02.txt AC 66 ms 66360 KB
sample_03.txt AC 62 ms 66248 KB