답안 #255600

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
255600 2020-08-01T12:02:20 Z amoo_safar Palindrome-Free Numbers (BOI13_numbers) C++14
71.25 / 100
1000 ms 384 KB
// Zende bad Shoma nasime faghat !
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ll Mod = 1000000007LL;
const int N = 20;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;

ll pw[N];

ll Solve(ll x){
	if(x < 0) return 0;
	vector<int> C;
	while(x){
		C.pb(x % 10);
		x /= 10;
	}
	ll res = 1;
	for(int i = 0; i < C.size() - 1; i++) res *= 10;

	reverse(all(C));
	for(int i = 0; i <= C.size(); i++){
		if(i == C.size()){
			res ++;
			break;
		}
		if(i == 0){
			if(C.size() == 1) res += C[0] - 1;
			else res += (C[0] - 1) * 9ll * pw[C.size() - 2];
		} else {
			for(int j = 0; j < C[i]; j++){
				if(j == C[i - 1]) continue;
				if((i >= 2) && (j == C[i - 2])) continue;
				res += pw[C.size() - i - 1];
			}
		}

		if((i >= 1) && (C[i] == C[i - 1])) break;
		if((i >= 2) && (C[i] == C[i - 2])) break;
	}


	return res;
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	pw[0] = 1;
	for(int i = 1; i < N; i++) pw[i] = 8 * pw[i - 1];  
	ll a, b;
	cin >> a >> b;
	cout << Solve(b) - Solve(a - 1) << '\n';
	return 0;
}

Compilation message

numbers.cpp: In function 'll Solve(ll)':
numbers.cpp:32:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < C.size() - 1; i++) res *= 10;
                 ~~^~~~~~~~~~~~~~
numbers.cpp:35:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i <= C.size(); i++){
                 ~~^~~~~~~~~~~
numbers.cpp:36:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(i == C.size()){
      ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Correct 0 ms 384 KB Output is correct
4 Incorrect 0 ms 384 KB Output isn't correct
5 Execution timed out 1094 ms 384 KB Time limit exceeded
6 Execution timed out 1092 ms 384 KB Time limit exceeded
7 Incorrect 0 ms 384 KB Output isn't correct
8 Incorrect 1 ms 384 KB Output isn't correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Incorrect 0 ms 384 KB Output isn't correct
15 Execution timed out 1089 ms 384 KB Time limit exceeded
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Execution timed out 1084 ms 384 KB Time limit exceeded
19 Correct 0 ms 384 KB Output is correct
20 Incorrect 0 ms 384 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Incorrect 0 ms 384 KB Output isn't correct
6 Correct 0 ms 384 KB Output is correct
7 Incorrect 0 ms 384 KB Output isn't correct
8 Incorrect 0 ms 384 KB Output isn't correct
9 Incorrect 1 ms 384 KB Output isn't correct
10 Incorrect 1 ms 384 KB Output isn't correct
11 Correct 1 ms 384 KB Output is correct
12 Incorrect 0 ms 384 KB Output isn't correct
13 Incorrect 0 ms 384 KB Output isn't correct
14 Incorrect 0 ms 384 KB Output isn't correct
15 Incorrect 0 ms 384 KB Output isn't correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 0 ms 384 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 0 ms 384 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 0 ms 384 KB Output is correct
35 Correct 0 ms 384 KB Output is correct
36 Correct 0 ms 384 KB Output is correct
37 Correct 0 ms 384 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 0 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 0 ms 384 KB Output is correct
42 Correct 0 ms 384 KB Output is correct
43 Correct 0 ms 384 KB Output is correct
44 Correct 0 ms 384 KB Output is correct
45 Correct 0 ms 384 KB Output is correct