Submission #48468

# Submission time Handle Problem Language Result Execution time Memory
48468 2018-05-13T18:29:13 Z rkocharyan Palindrome-Free Numbers (BOI13_numbers) C++14
35 / 100
1000 ms 672 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;
	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:62: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:68: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]) {
                    ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 22 ms 376 KB Output is correct
4 Correct 13 ms 376 KB Output is correct
5 Correct 2 ms 428 KB Output is correct
6 Correct 2 ms 568 KB Output is correct
7 Correct 2 ms 628 KB Output is correct
8 Correct 2 ms 628 KB Output is correct
9 Correct 2 ms 628 KB Output is correct
10 Correct 2 ms 672 KB Output is correct
11 Correct 2 ms 672 KB Output is correct
12 Correct 2 ms 672 KB Output is correct
13 Correct 2 ms 672 KB Output is correct
14 Correct 14 ms 672 KB Output is correct
15 Correct 13 ms 672 KB Output is correct
16 Correct 3 ms 672 KB Output is correct
17 Correct 6 ms 672 KB Output is correct
18 Correct 2 ms 672 KB Output is correct
19 Correct 22 ms 672 KB Output is correct
20 Correct 13 ms 672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 852 ms 672 KB Output is correct
2 Execution timed out 1088 ms 672 KB Time limit exceeded
3 Execution timed out 1084 ms 672 KB Time limit exceeded
4 Execution timed out 1081 ms 672 KB Time limit exceeded
5 Execution timed out 1084 ms 672 KB Time limit exceeded
6 Execution timed out 1083 ms 672 KB Time limit exceeded
7 Correct 403 ms 672 KB Output is correct
8 Correct 281 ms 672 KB Output is correct
9 Correct 510 ms 672 KB Output is correct
10 Correct 689 ms 672 KB Output is correct
11 Correct 854 ms 672 KB Output is correct
12 Execution timed out 1088 ms 672 KB Time limit exceeded
13 Execution timed out 1084 ms 672 KB Time limit exceeded
14 Execution timed out 1086 ms 672 KB Time limit exceeded
15 Execution timed out 1087 ms 672 KB Time limit exceeded
16 Execution timed out 1087 ms 672 KB Time limit exceeded
17 Execution timed out 1083 ms 672 KB Time limit exceeded
18 Execution timed out 1089 ms 672 KB Time limit exceeded
19 Execution timed out 1088 ms 672 KB Time limit exceeded
20 Execution timed out 1090 ms 672 KB Time limit exceeded
21 Execution timed out 1079 ms 672 KB Time limit exceeded
22 Execution timed out 1091 ms 672 KB Time limit exceeded
23 Execution timed out 1080 ms 672 KB Time limit exceeded
24 Execution timed out 1086 ms 672 KB Time limit exceeded
25 Execution timed out 1083 ms 672 KB Time limit exceeded
26 Execution timed out 1077 ms 672 KB Time limit exceeded
27 Execution timed out 1087 ms 672 KB Time limit exceeded
28 Execution timed out 1076 ms 672 KB Time limit exceeded
29 Execution timed out 1077 ms 672 KB Time limit exceeded
30 Execution timed out 1086 ms 672 KB Time limit exceeded
31 Execution timed out 1085 ms 672 KB Time limit exceeded
32 Execution timed out 1078 ms 672 KB Time limit exceeded
33 Execution timed out 1089 ms 672 KB Time limit exceeded
34 Execution timed out 1087 ms 672 KB Time limit exceeded
35 Execution timed out 1090 ms 672 KB Time limit exceeded
36 Execution timed out 1089 ms 672 KB Time limit exceeded
37 Execution timed out 1083 ms 672 KB Time limit exceeded
38 Execution timed out 1078 ms 672 KB Time limit exceeded
39 Execution timed out 1085 ms 672 KB Time limit exceeded
40 Execution timed out 1088 ms 672 KB Time limit exceeded
41 Execution timed out 1089 ms 672 KB Time limit exceeded
42 Execution timed out 1093 ms 672 KB Time limit exceeded
43 Execution timed out 1089 ms 672 KB Time limit exceeded
44 Execution timed out 1078 ms 672 KB Time limit exceeded
45 Execution timed out 1083 ms 672 KB Time limit exceeded