답안 #48470

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
48470 2018-05-13T18:31:41 Z rkocharyan Palindrome-Free Numbers (BOI13_numbers) C++14
25 / 100
24 ms 628 KB
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <bitset>
#include <iomanip>
#include <memory>
#include <functional>
#include <numeric>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <climits>
#include <cassert>
using namespace std;

#define rep(i, x, y) for(int i = x; i <= y; ++i)
#define mp make_pair
#define add push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mem(a,b) memset(a, b, sizeof(a))
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:20000007")
#pragma GCC optimize("unroll-loops")

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef pair <int, int> pii;
typedef vector <int> lnum;

const int N = (int)1e6 + 100;
const int maxn = (int)1e3 + 100;
const int base = (int)1e9;
const int mod = (int)1e9 + 7;
const int inf = INT_MAX;
const long long ll_inf = LLONG_MAX;
const long double PI = acos((long double)-1.0);
const long double eps = 1e-8;

void solve() {
	long long l, r; cin >> l >> r;
	if (r - l > N) {
		cout << (r - l) / 2 << '\n';
		return;
	}
	long long ans = 0;
	for (long long i = l; i <= r; ++i) {
		string now = to_string(i);
		bool pal2, pal3;
		pal2 = pal3 = 1;
		if (now.size() >= 2) {
			for (int j = 0; j < now.size() - 1; ++j) if (now[j] == now[j + 1]) {
				pal2 = 0;
				break;
			}
		}
		if (now.size() >= 3) {
			for (int j = 0; j < now.size() - 2; ++j) if (now[j] == now[j + 2]) {
				pal3 = 0;
				break;
			}
		}
		ans += (pal2 & pal3);
	}
	cout << ans << '\n';
}

int main() {
	//ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

	//#define Freopen
#ifdef Freopen
#ifndef _MSC_VER 
#define TASK ""
	freopen(TASK".in", "r", stdin);
	freopen(TASK".out", "w", stdout);
#endif
#endif

	int T = 1;
	//scanf("%d", &T);

	for (; T; --T) solve();

#ifdef DEBUG
	cerr << double(1.0 * clock() / CLOCKS_PER_SEC) << '\n';
#endif 

	return 0;
}

Compilation message

numbers.cpp:34:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning(disable:4996)
 
numbers.cpp:35:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment(linker, "/STACK:20000007")
 
numbers.cpp: In function 'void solve()':
numbers.cpp:66:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int j = 0; j < now.size() - 1; ++j) if (now[j] == now[j + 1]) {
                    ~~^~~~~~~~~~~~~~~~
numbers.cpp:72:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int j = 0; j < now.size() - 2; ++j) if (now[j] == now[j + 2]) {
                    ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 24 ms 396 KB Output is correct
4 Correct 12 ms 408 KB Output is correct
5 Correct 2 ms 476 KB Output is correct
6 Correct 2 ms 500 KB Output is correct
7 Correct 2 ms 500 KB Output is correct
8 Correct 2 ms 500 KB Output is correct
9 Correct 2 ms 500 KB Output is correct
10 Correct 2 ms 500 KB Output is correct
11 Correct 2 ms 560 KB Output is correct
12 Correct 2 ms 560 KB Output is correct
13 Correct 1 ms 560 KB Output is correct
14 Correct 12 ms 560 KB Output is correct
15 Correct 12 ms 560 KB Output is correct
16 Correct 2 ms 560 KB Output is correct
17 Correct 5 ms 560 KB Output is correct
18 Correct 2 ms 560 KB Output is correct
19 Correct 21 ms 560 KB Output is correct
20 Correct 12 ms 560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 560 KB Output isn't correct
2 Incorrect 2 ms 628 KB Output isn't correct
3 Incorrect 2 ms 628 KB Output isn't correct
4 Incorrect 2 ms 628 KB Output isn't correct
5 Incorrect 2 ms 628 KB Output isn't correct
6 Incorrect 2 ms 628 KB Output isn't correct
7 Incorrect 1 ms 628 KB Output isn't correct
8 Incorrect 2 ms 628 KB Output isn't correct
9 Incorrect 2 ms 628 KB Output isn't correct
10 Incorrect 2 ms 628 KB Output isn't correct
11 Incorrect 2 ms 628 KB Output isn't correct
12 Incorrect 2 ms 628 KB Output isn't correct
13 Incorrect 2 ms 628 KB Output isn't correct
14 Incorrect 2 ms 628 KB Output isn't correct
15 Incorrect 2 ms 628 KB Output isn't correct
16 Incorrect 1 ms 628 KB Output isn't correct
17 Incorrect 1 ms 628 KB Output isn't correct
18 Incorrect 1 ms 628 KB Output isn't correct
19 Incorrect 1 ms 628 KB Output isn't correct
20 Incorrect 2 ms 628 KB Output isn't correct
21 Incorrect 2 ms 628 KB Output isn't correct
22 Incorrect 1 ms 628 KB Output isn't correct
23 Incorrect 2 ms 628 KB Output isn't correct
24 Incorrect 2 ms 628 KB Output isn't correct
25 Incorrect 1 ms 628 KB Output isn't correct
26 Incorrect 1 ms 628 KB Output isn't correct
27 Incorrect 1 ms 628 KB Output isn't correct
28 Incorrect 2 ms 628 KB Output isn't correct
29 Incorrect 2 ms 628 KB Output isn't correct
30 Incorrect 1 ms 628 KB Output isn't correct
31 Incorrect 2 ms 628 KB Output isn't correct
32 Incorrect 2 ms 628 KB Output isn't correct
33 Incorrect 2 ms 628 KB Output isn't correct
34 Incorrect 2 ms 628 KB Output isn't correct
35 Incorrect 2 ms 628 KB Output isn't correct
36 Incorrect 2 ms 628 KB Output isn't correct
37 Incorrect 2 ms 628 KB Output isn't correct
38 Incorrect 2 ms 628 KB Output isn't correct
39 Incorrect 2 ms 628 KB Output isn't correct
40 Incorrect 2 ms 628 KB Output isn't correct
41 Incorrect 2 ms 628 KB Output isn't correct
42 Incorrect 2 ms 628 KB Output isn't correct
43 Incorrect 2 ms 628 KB Output isn't correct
44 Incorrect 2 ms 628 KB Output isn't correct
45 Incorrect 2 ms 628 KB Output isn't correct