답안 #384435

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
384435 2021-04-01T16:38:39 Z negar_a Pipes (BOI13_pipes) C++14
3.88889 / 100
2 ms 640 KB
//!yrt tsuj uoy srettam gnihton no emoc
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define pii pair <int, int>
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define F first
#define S second

ll a, b, ans = 0;
ll x, y;
string A, B;

ll pw(ll x, ll y){
	ll res = 1;
	for(ll i = 0; i < y; i ++){
		res *= x;
	}
	return res;
}

bool Y(int l, int r, int m){
	return (m > l && m < r);
}

void solve_s(ll st){
	for(ll i = st - 1; i >= 0; i --){
		ll t = 9 - (A[i] - '0') - (i < x - 1 && A[i + 1] > A[i]) - (i < x - 2 && A[i + 2] > A[i]);
		ans += 1LL * t * (i == x - 1 ? 9 * pw(8, i - 1) : pw(8, i));
		if(i < x - 1 && A[i] == A[i + 1]){
			return;
		}
		if(i < x - 2 && A[i] == A[i + 2]){
			return;
		}
	}
	if(0 < x - 1 && A[0] == A[1]){
		return;
	}
	if(0 < x - 2 && A[0] == A[2]){
		return;
	}
	ans ++;
	return;
}

void solve_b(ll st){
	for(ll i = st - 1; i >= 0; i --){
		ll t = (B[i] - '0' - (i == y - 1)) - (i < y - 1 && B[i + 1] < B[i]) - (i < y - 2 && B[i + 2] < B[i]);
		ans += 1LL * t * (i == y - 1 ? 9 * pw(8, i - 1) : pw(8, i));
		if(i < y - 1 && B[i] == B[i + 1]){
			return;
		}
		if(i < y - 2 && B[i] == B[i + 2]){
			return;
		}
//		cout << "ani = " << i << " : " << ans << endl;
	}
	if(0 < y - 1 && B[0] == B[1]){
		return;
	}
	if(0 < y - 2 && B[0] == B[2]){
		return;
	}
	ans ++;
	return;
}

int main(){
	fast_io;
		
	cin >> a >> b;
	A = to_string(a);
	B = to_string(b);
	x = A.size(), y = B.size();
	
	reverse(A.begin(), A.end());
	reverse(B.begin(), B.end());
	
	if(x == y){
		assert(0);
		ll ind = x - 1;
		while(ind >= 0 && A[ind] == B[ind]){
			if(ind < x - 1 && A[ind] == A[ind + 1]){
				cout << 0;
				return 0;
			}
			if(ind < x - 2 && A[ind] == A[ind + 2]){
				cout << 0;
				return 0;
			}
			ind --;
		}
		if(ind >= 0){
			ll t = 1LL * (B[ind] - A[ind]) - 1 - (ind + 1 < x && Y(A[ind], B[ind], A[ind + 1])) - (ind + 2 < x && Y(A[ind], B[ind], A[ind + 2]));
			ans += t * (ind == x - 1 ? 9 * pw(8, ind - 1) : pw(8, ind));
			
			solve_s(ind);
			solve_b(ind);
		}else
			ans = 1;
	}else{
		for(ll i = x + 1; i < y; i ++){
			ans += 1LL * 9 * 9 * pw(8, i - 2);
		}
		solve_s(x);
		solve_b(y);
	}
	
	cout << ans;
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 6
2 Incorrect 1 ms 364 KB Output isn't correct
3 Runtime error 1 ms 492 KB Execution killed with signal 6
4 Runtime error 2 ms 492 KB Execution killed with signal 6
5 Runtime error 1 ms 492 KB Execution killed with signal 6
6 Runtime error 1 ms 492 KB Execution killed with signal 6
7 Incorrect 1 ms 364 KB Output isn't correct
8 Incorrect 1 ms 364 KB Output isn't correct
9 Runtime error 2 ms 492 KB Execution killed with signal 6
10 Runtime error 2 ms 492 KB Execution killed with signal 6
11 Incorrect 1 ms 364 KB Output isn't correct
12 Runtime error 2 ms 492 KB Execution killed with signal 6
13 Runtime error 1 ms 492 KB Execution killed with signal 6
14 Runtime error 1 ms 492 KB Execution killed with signal 6
15 Runtime error 1 ms 492 KB Execution killed with signal 6
16 Runtime error 1 ms 492 KB Execution killed with signal 6
17 Runtime error 2 ms 620 KB Execution killed with signal 6
18 Incorrect 1 ms 364 KB Output isn't correct
19 Incorrect 1 ms 364 KB Output isn't correct
20 Runtime error 2 ms 492 KB Execution killed with signal 6
21 Runtime error 2 ms 492 KB Execution killed with signal 6
22 Runtime error 2 ms 492 KB Execution killed with signal 6
23 Runtime error 2 ms 492 KB Execution killed with signal 6
24 Incorrect 1 ms 364 KB Output isn't correct
25 Runtime error 2 ms 492 KB Execution killed with signal 6
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 492 KB Execution killed with signal 6
2 Runtime error 2 ms 492 KB Execution killed with signal 6
3 Runtime error 2 ms 492 KB Execution killed with signal 6
4 Runtime error 2 ms 556 KB Execution killed with signal 6
5 Runtime error 1 ms 492 KB Execution killed with signal 6
6 Runtime error 1 ms 492 KB Execution killed with signal 6
7 Runtime error 2 ms 492 KB Execution killed with signal 6
8 Runtime error 2 ms 492 KB Execution killed with signal 6
9 Runtime error 2 ms 492 KB Execution killed with signal 6
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Incorrect 1 ms 364 KB Output isn't correct
13 Incorrect 1 ms 364 KB Output isn't correct
14 Runtime error 2 ms 492 KB Execution killed with signal 6
15 Runtime error 2 ms 492 KB Execution killed with signal 6
16 Runtime error 2 ms 492 KB Execution killed with signal 6
17 Runtime error 2 ms 492 KB Execution killed with signal 6
18 Runtime error 1 ms 492 KB Execution killed with signal 6
19 Runtime error 1 ms 492 KB Execution killed with signal 6
20 Incorrect 1 ms 384 KB Output isn't correct
21 Incorrect 1 ms 364 KB Output isn't correct
22 Runtime error 1 ms 492 KB Execution killed with signal 6
23 Runtime error 1 ms 492 KB Execution killed with signal 6
24 Runtime error 2 ms 492 KB Execution killed with signal 6
25 Runtime error 2 ms 492 KB Execution killed with signal 6
26 Runtime error 2 ms 492 KB Execution killed with signal 6
27 Runtime error 2 ms 492 KB Execution killed with signal 6
28 Incorrect 1 ms 364 KB Output isn't correct
29 Incorrect 1 ms 364 KB Output isn't correct
30 Runtime error 2 ms 492 KB Execution killed with signal 6
31 Runtime error 1 ms 492 KB Execution killed with signal 6
32 Runtime error 2 ms 492 KB Execution killed with signal 6
33 Runtime error 2 ms 492 KB Execution killed with signal 6
34 Runtime error 1 ms 492 KB Execution killed with signal 6
35 Runtime error 1 ms 492 KB Execution killed with signal 6
36 Correct 1 ms 364 KB Output is correct
37 Runtime error 2 ms 492 KB Execution killed with signal 6
38 Runtime error 2 ms 640 KB Execution killed with signal 6
39 Runtime error 2 ms 492 KB Execution killed with signal 6
40 Runtime error 2 ms 640 KB Execution killed with signal 6
41 Runtime error 1 ms 492 KB Execution killed with signal 6
42 Runtime error 1 ms 492 KB Execution killed with signal 6
43 Runtime error 2 ms 492 KB Execution killed with signal 6
44 Runtime error 2 ms 492 KB Execution killed with signal 6
45 Incorrect 1 ms 364 KB Output isn't correct
46 Runtime error 2 ms 492 KB Execution killed with signal 6
47 Runtime error 2 ms 492 KB Execution killed with signal 6
48 Runtime error 2 ms 492 KB Execution killed with signal 6
49 Runtime error 2 ms 492 KB Execution killed with signal 6
50 Runtime error 2 ms 492 KB Execution killed with signal 6
51 Runtime error 2 ms 492 KB Execution killed with signal 6
52 Runtime error 2 ms 492 KB Execution killed with signal 6
53 Incorrect 1 ms 364 KB Output isn't correct
54 Runtime error 2 ms 492 KB Execution killed with signal 6