답안 #635066

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
635066 2022-08-25T11:22:42 Z pragmatist 생물 실험 (IZhO13_expgorl) C++17
100 / 100
8 ms 348 KB
    #include<bits/stdc++.h>
     
    #define ll long long
    #define pb push_back
    #define x first
    #define y second
    #define sz(v) (int)v.size()
    #define all(v) v.begin(), v.end()
    #define ld long double
    #define int long long
    #define nl "\n"
     
    using namespace std;
    using pii = pair<int, int>;
     
    const int N = (int)1e5 + 7;
    const int inf = (int)1e9 + 7;
    const ll INF = (ll)2e18 + 7;
    const int MOD = (int)1e9 + 7;
    const int M = (int)5e4 + 7; 
     
    int k, Lx, Ly, Gx, Gy, dx, dy;
    string a;
     
    ll mx, mn;
     
    ll dist(int x1, int y1, int x2, int y2) {
    	return 1ll * (x1 - x2) * (x1 - x2) + 1ll * (y1 - y2) * (y1 - y2);
    }
     
    void upd(int curx, int cury, int x) {
    	mn = min(mn, dist(Gx + curx + x * dx, Gy + cury + x * dy, Lx, Ly));
       	mx = max(mx, dist(Gx + curx + x * dx, Gy + cury + x * dy, Lx, Ly));        			
    }
     
    void solve() {
    	cin >> k >> a >> Lx >> Ly >> Gx >> Gy;
    	mn = INF, mx = -INF;
    	mn = min(mn, dist(Gx, Gy, Lx, Ly));
    	mx = max(mx, dist(Gx, Gy, Lx, Ly));
    	int curx = 0, cury = 0;
     
    	for(auto x : a) {
    		if(x == 'L') dx--;
    		if(x == 'R') dx++;
    		if(x == 'F') dy++;
    		if(x == 'B') dy--; 
    	}
    	for(auto x : a) {
    		if(x == 'L') curx--;
    		if(x == 'R') curx++;
    		if(x == 'F') cury++;
    		if(x == 'B') cury--;
    		int l = 0, r = k - 1;
    	    while(l <= r) {
    			int m1 = l + (r - l) / 3;
    			int m2 = r - (r - l) / 3;
    			
    			upd(curx, cury, m1);
    			upd(curx, cury, m2);
    			if(dist(Gx + curx + m1 * dx, Gy + cury + m1 * dy, Lx, Ly) < dist(Gx + curx + m2 * dx, Gy + cury + m2 * dy, Lx, Ly)) {
    				r = m2 - 1;
    			} else
    				l = m1 + 1;
    		}
    		l = 0, r = k - 1;
    	    while(l <= r) {
    			int m1 = l + (r - l) / 3;
    			int m2 = r - (r - l) / 3;
    			
    			upd(curx, cury, m1);
    			upd(curx, cury, m2);
    			if(dist(Gx + curx + m1 * dx, Gy + cury + m1 * dy, Lx, Ly) > dist(Gx + curx + m2 * dx, Gy + cury + m2 * dy, Lx, Ly)) {
    				r = m2 - 1;
    			} else
    				l = m1 + 1;
    		}
    	  	upd(curx, cury, k - 1);
    	   	upd(curx, cury, 0);
    	}
    	cout << fixed << setprecision(9) << sqrt(mn) << ' ' << sqrt(mx) << nl;
    }
     
    signed main() {
    	ios_base::sync_with_stdio(NULL);
    	cin.tie(0);
    	cout.tie(0);
    	int test = 1;
    	//cin >> test;
    	while(test--) {
    		solve();
    	}
    	return 0;
    }
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 5 ms 324 KB Output is correct
10 Correct 6 ms 332 KB Output is correct
11 Correct 3 ms 212 KB Output is correct
12 Correct 8 ms 336 KB Output is correct
13 Correct 7 ms 344 KB Output is correct
14 Correct 5 ms 212 KB Output is correct
15 Correct 6 ms 340 KB Output is correct
16 Correct 6 ms 348 KB Output is correct
17 Correct 6 ms 340 KB Output is correct
18 Correct 6 ms 340 KB Output is correct
19 Correct 7 ms 340 KB Output is correct
20 Correct 7 ms 340 KB Output is correct