Submission #3882762
Source Code Expand
# include <bits/stdc++.h>
# define x first
# define y second
# define mp make_pair
// everything goes according to my plan
# define pb push_back
# define sz(a) (int)(a.size())
# define vec vector
// shimkenttin kyzdary, dzyn, dzyn, dzyn...
# define y1 Y_U_NO_y1
# define left Y_U_NO_left
# define right Y_U_NO_right
# ifdef Local
# define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
# else
# define debug(...) (__VA_ARGS__)
# define cerr if(0)cout
# endif
using namespace std;
typedef pair <int, int> pii;
typedef long long ll;
typedef long double ld;
const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 4e18;
const int Sz = 1110111;
// a pinch of soul
inline void Read_rap () {
ios_base :: sync_with_stdio(0);
cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
unsigned int seed;
asm ("rdtsc" : "=A"(seed));
srand (seed);
}
void files (string problem) {
if (fopen ((problem + ".in").c_str(),"r")) {
freopen ((problem + ".in").c_str(),"r",stdin);
freopen ((problem + ".out").c_str(),"w",stdout);
}
}
void localInput(const char in[] = "s") {
if (fopen (in, "r")) {
freopen (in, "r", stdin);
}
else
cerr << "Warning: Input file not found" << endl;
}
int n;
int a[Sz];
bool check (int x) {
static map <int, int> s;
s.clear();
for (int i = 1; i <= n; i++) {
if (a[i - 1] >= a[i]) {
while (!s.empty() && s.rbegin()->x > a[i])
s.erase (--s.end());
int l = a[i];
while (s[l] == x-1) {
if (l == 1)
return 0;
s.erase (l--);
}
s[l]++;
}
}
return 1;
}
int main()
{
# ifdef Local
//localInput();
# endif
Read_rap();
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++) {
if (i == n) {
cout << 1;
return 0;
}
if (a[i] <= a[i - 1])
break;
}
int l = 2, r = n, ans = r;
while (l <= r) {
int mid = (l+r) >> 1;
if (check(mid))
ans = mid, r = mid-1;
else
l = mid+1;
}
cout << ans;
return 0;
}
// Coded by Z..
Submission Info
| Submission Time |
|
| Task |
C - Lexicographic constraints |
| User |
Zhanbolat |
| Language |
C++14 (GCC 5.4.1) |
| Score |
700 |
| Code Size |
2226 Byte |
| Status |
AC |
| Exec Time |
236 ms |
| Memory |
1024 KiB |
Compile Error
./Main.cpp: In function ‘void files(std::string)’:
./Main.cpp:45:50: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
freopen ((problem + ".in").c_str(),"r",stdin);
^
./Main.cpp:46:52: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
freopen ((problem + ".out").c_str(),"w",stdout);
^
./Main.cpp: In function ‘void localInput(const char*)’:
./Main.cpp:51:29: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
freopen (in, "r", stdin);
^
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
700 / 700 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
sample01.txt, sample02.txt |
| All |
sample01.txt, sample02.txt, in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, sample01.txt, sample02.txt |
| Case Name |
Status |
Exec Time |
Memory |
| in01.txt |
AC |
166 ms |
1024 KiB |
| in02.txt |
AC |
165 ms |
1024 KiB |
| in03.txt |
AC |
166 ms |
1024 KiB |
| in04.txt |
AC |
159 ms |
1024 KiB |
| in05.txt |
AC |
162 ms |
1024 KiB |
| in06.txt |
AC |
160 ms |
1024 KiB |
| in07.txt |
AC |
162 ms |
1024 KiB |
| in08.txt |
AC |
164 ms |
1024 KiB |
| in09.txt |
AC |
54 ms |
1024 KiB |
| in10.txt |
AC |
85 ms |
1024 KiB |
| in11.txt |
AC |
87 ms |
1024 KiB |
| in12.txt |
AC |
111 ms |
1024 KiB |
| in13.txt |
AC |
105 ms |
1024 KiB |
| in14.txt |
AC |
236 ms |
1024 KiB |
| in15.txt |
AC |
24 ms |
1024 KiB |
| in16.txt |
AC |
235 ms |
1024 KiB |
| in17.txt |
AC |
25 ms |
1024 KiB |
| in18.txt |
AC |
1 ms |
256 KiB |
| in19.txt |
AC |
17 ms |
1024 KiB |
| in20.txt |
AC |
78 ms |
1024 KiB |
| in21.txt |
AC |
80 ms |
1024 KiB |
| in22.txt |
AC |
82 ms |
1024 KiB |
| in23.txt |
AC |
71 ms |
1024 KiB |
| in24.txt |
AC |
83 ms |
1024 KiB |
| in25.txt |
AC |
74 ms |
1024 KiB |
| in26.txt |
AC |
71 ms |
1024 KiB |
| in27.txt |
AC |
63 ms |
1024 KiB |
| sample01.txt |
AC |
1 ms |
256 KiB |
| sample02.txt |
AC |
1 ms |
256 KiB |