Submission #501477

# Submission time Handle Problem Language Result Execution time Memory
501477 2022-01-03T12:13:50 Z keta_tsimakuridze Experiments with Gorlum (IZhO13_expgorl) C++14
0 / 100
1 ms 204 KB
#include<bits/stdc++.h>
#define int long long
#define f first
#define s second
#define pii pair<int,int>
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7; // !
int t;
main(){
	int K;
	cin >> K;
	string s;
	cin >> s;
	int n = s.size(); s = '#' + s;
	int dx = 0, dy = 0;
	for(int i = 1; i <= n; i++) {
		if(s[i] == 'L') dx--;
		else if(s[i] == 'R') dx++;
		else if(s[i] == 'F') dy++;
		else if(s[i] != 'I')dy--; 
	}
	int x, y, X_, Y_, ans_min = 1e18, ans_max = 0;
	cin >> x >> y;
	cin >> X_ >> Y_;
	for(int i = 0; i <= K; i++) {
		int X = (x + i * dx - X_) * (x + i * dx - X_) + (y + i * dy - Y_) * (y + i * dy - Y_);
		ans_min = min(ans_min, X);
		ans_max = max(ans_max, X);
	}
	for(int i = 1; i <= n; i++) {
		if(s[i] == 'L') x--;
		else if(s[i] == 'R') x++;
		else if(s[i] == 'F') y++;
		else if(s[i] != 'I')y--;		
	 //	(x + dx * k - X_) ^ 2 + (y + dy * k - Y_) ^ 2
	 // k^2 * (dx^2 + dy^2) + 2 * k * (y * dy + x * dx - dy * Y_ - dx * X_)
	 // k aris [0 ... K - 1] shualedshi	
	 	int a = dx * dx + dy * dy, b = 2 * (y * dy + x * dx - dy * Y_ - dx * X_),
	 		c = x * x + X_ * X_ - 2 * x * X_ + y * y + Y_ * Y_ - 2 * y * Y_;
	 	if(a == 0) {
	 		ans_min = min(ans_min, c);
	 		ans_min = min(ans_min, a * (K - 1) * (K - 1) + b * (K - 1) + c);
	 		ans_max = max(ans_max, a * (K - 1) * (K - 1) + b * (K - 1) + c);
	 		ans_max = max(ans_max, c);
	 		continue;
		 }
	 	double k_ = - b / (double)(2 * a);
	 	if(k_ <= 0) ans_min = min(ans_min, c);
	 	else if(k_ >= K - 1) ans_min = min(ans_min, a * (K - 1) * (K - 1) + b * (K - 1) + c);
	 	else {
	 		int p = k_;
		 	ans_min = min(ans_min, a * p * p + b * p + c);
		 	k_++;
		 	p = k_;
		 	ans_min = min(ans_min, a * p * p + b * p + c);
		 }
	 	ans_max = max(ans_max, max(0ll, a * (K - 1) * (K - 1) + b * (K - 1)) + c );
	}
	cout <<fixed << setprecision(9) << (double)sqrtl((double)ans_min) <<" " << (double)sqrtl((double)ans_max);
}

Compilation message

expgorl.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    9 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -