# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
501478 | keta_tsimakuridze | Experiments with Gorlum (IZhO13_expgorl) | C++14 | 2 ms | 332 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |