답안 #313331

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
313331 2020-10-15T18:15:22 Z vitkishloh228 생물 실험 (IZhO13_expgorl) C++14
100 / 100
318 ms 504 KB
#include <bits/stdc++.h>
 
#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define all(s) s.begin(),s.end()
//#define int long long
 
using namespace std;
 
const int N = (1e6 + 12);
const int mod = (1e9 + 7);
const int INF = (0x3f3f3f3f);
 
int lx, ly;
double ansmin, ansmax;
double dist(double x, double y){
	return sqrt((x - lx) * (x - lx) + (y - ly) * (y - ly)); 
}
 
string s;
double gx, gy, x = 0, y = 0;
void check(int val){
	double gxx = gx + val * x, gyy = gy + val * y;
	ansmin = min(ansmin, dist(gxx, gyy));
	ansmax = max(ansmax, dist(gxx, gyy));
	for(int i = 0;i < s.size(); i++){
		if(s[i] == 'L'){
			gxx--;
		}
		if(s[i] == 'R'){
			gxx++;
		}
		if(s[i] == 'F'){
			gyy++;
		}
		if(s[i] == 'B'){
			gyy--;
		}
		ansmin = min(ansmin, dist(gxx, gyy));
		ansmax = max(ansmax, dist(gxx, gyy));
	}
}
main()
{
	int k;
	scanf("%d", &k);
	cin >> s;
	cin >> lx >> ly;
	cin >> gx >> gy;
	ansmin = dist(gx, gy), ansmax = dist(gx, gy);
	for(int i = 0;i < s.size(); i++){
		if(s[i] == 'L'){
			x--;
		}
		if(s[i] == 'R'){
			x++;
		}
		if(s[i] == 'F'){
			y++;
		}
		if(s[i] == 'B'){
			y--;
		}
	}
	for(int i = 0;i <= min(k - 1, 1000); i++){
		check(i);
	}
	for(int i = max(1001, k - 1000);i <= k - 1; i++){
		check(i);
	}
	cout << fixed << setprecision(9) << ansmin << " " << ansmax;
}

Compilation message

expgorl.cpp: In function 'void check(int)':
expgorl.cpp:28:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |  for(int i = 0;i < s.size(); i++){
      |                ~~^~~~~~~~~~
expgorl.cpp: At global scope:
expgorl.cpp:45:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   45 | main()
      |      ^
expgorl.cpp: In function 'int main()':
expgorl.cpp:53:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |  for(int i = 0;i < s.size(); i++){
      |                ~~^~~~~~~~~~
expgorl.cpp:48:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   48 |  scanf("%d", &k);
      |  ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 256 KB Output is correct
2 Correct 45 ms 376 KB Output is correct
3 Correct 53 ms 376 KB Output is correct
4 Correct 55 ms 256 KB Output is correct
5 Correct 33 ms 376 KB Output is correct
6 Correct 37 ms 256 KB Output is correct
7 Correct 58 ms 376 KB Output is correct
8 Correct 53 ms 256 KB Output is correct
9 Correct 191 ms 504 KB Output is correct
10 Correct 289 ms 400 KB Output is correct
11 Correct 164 ms 504 KB Output is correct
12 Correct 309 ms 404 KB Output is correct
13 Correct 307 ms 504 KB Output is correct
14 Correct 246 ms 384 KB Output is correct
15 Correct 245 ms 384 KB Output is correct
16 Correct 211 ms 400 KB Output is correct
17 Correct 215 ms 384 KB Output is correct
18 Correct 317 ms 384 KB Output is correct
19 Correct 318 ms 504 KB Output is correct
20 Correct 315 ms 384 KB Output is correct