#include <bits/stdc++.h>
//#include "functions.h"
#define FOR(x,y) for(int x = 0; x < y; x++)
#define ALLR(x) x.begin(),x.end()
#define con continue
#define ll long long
#define LINF LLONG_MAX
#define INF INT_MAX
#define pii pair<int,int>
#define vi vector <int>
#define pb push_back
#define F first
#define S second
#define len(x) x.length()
#define sz(x) x.size()
#define SEE(v) for(auto x : v) cout << x << " "; cout << endl;
using namespace std;
void rec(ll &ans, vector <ll> vans, vector <vector<ll> > &vector_of_ans){
FOR(j, sz(vans))
{
if(vans[j] == 0 || vans[j] == 1) con;
ll temp = vans[j];
vans.erase(vans.begin() + j);
//int pos1 = lower_bound(ALLR(vans), temp - 1) - vans.begin();
//int pos2 = lower_bound(ALLR(vans), temp - 2) - vans.begin();
if(find(ALLR(vans), temp - 1) == vans.end() && find(ALLR(vans), temp - 2) == vans.end())
{
vector <ll> vtemp = vans;
int pos2 = lower_bound(ALLR(vtemp), temp - 2) - vtemp.begin();
vtemp.insert(vtemp.begin() + pos2, temp - 2);
int pos1 = lower_bound(ALLR(vtemp), temp - 1) - vtemp.begin();
vtemp.insert(vtemp.begin() + pos1, temp - 1);
bool is_ans = true;
FOR(k, sz(vector_of_ans))
{
if(vector_of_ans[k] == vtemp) is_ans = false;
}
if(is_ans)
{
vector_of_ans.pb(vtemp);
ans++;
}
// SEE(vtemp);
rec(ans, vtemp, vector_of_ans);
//vtemp.erase(vans.begin() + pos1);
//vans.erase(vans.begin() + pos2);
}
vans.insert(vans.begin() + j, temp);
}
}
int main() {
//freopen("test.txt","r",stdin);
int n;
cin >> n;
vector <vector <ll> > vector_of_ans;
vector <ll> num(n), t;
FOR(j, n) cin >> num[j];
FOR(cuiwbdcw, n)
{
int pos = lower_bound(ALLR(t), num[cuiwbdcw] - 1) - t.begin();
t.insert(t.begin() + pos, num[cuiwbdcw] - 1);
//SEE(t);
for(int j = sz(t) - 1; j >= 0; j--)
{
if(j != 0)
{
if(t[j] == t[j - 1] + 1)
{
int bigger = t[j] + 1;
t.erase(t.begin() + j - 1);
t.erase(t.begin() + j - 1);
int pos = lower_bound(ALLR(t), bigger) - t.begin();
t.insert(t.begin() + pos, bigger);
j += 2;
}
else if(t[j] == t[j - 1])
{
int same = t[j];
t.erase(t.begin() + j - 1);
t.erase(t.begin() + j - 1);
int pos = lower_bound(ALLR(t), same - 2) - t.begin();
if(same - 2 >= 0) t.insert(t.begin() + pos, same - 2);
pos = lower_bound(ALLR(t), same + 1) - t.begin();
t.insert(t.begin() + pos, same + 1);
j += 2;
}
}
if(j > sz(t)) j = sz(t);
}
//SEE(t);
ll ans = 1;
vector <ll> vans = t;
rec(ans, vans, vector_of_ans);
cout << ans << endl;
}
}
Compilation message
fib.cpp: In function 'void rec(long long int&, std::vector<long long int>, std::vector<std::vector<long long int> >&)':
fib.cpp:3:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define FOR(x,y) for(int x = 0; x < y; x++)
^
fib.cpp:19:2: note: in expansion of macro 'FOR'
FOR(j, sz(vans))
^~~
fib.cpp:3:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define FOR(x,y) for(int x = 0; x < y; x++)
^
fib.cpp:40:4: note: in expansion of macro 'FOR'
FOR(k, sz(vector_of_ans))
^~~
fib.cpp: In function 'int main()':
fib.cpp:108:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(j > sz(t)) j = sz(t);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
4 ms |
356 KB |
Output is correct |
3 |
Correct |
4 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
504 KB |
Output is correct |
6 |
Correct |
18 ms |
660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
4 ms |
356 KB |
Output is correct |
3 |
Correct |
4 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
504 KB |
Output is correct |
6 |
Correct |
18 ms |
660 KB |
Output is correct |
7 |
Incorrect |
6 ms |
660 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4017 ms |
3340 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
4 ms |
356 KB |
Output is correct |
3 |
Correct |
4 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
504 KB |
Output is correct |
6 |
Correct |
18 ms |
660 KB |
Output is correct |
7 |
Incorrect |
6 ms |
660 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
599 ms |
263168 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
4 ms |
356 KB |
Output is correct |
3 |
Correct |
4 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
504 KB |
Output is correct |
6 |
Correct |
18 ms |
660 KB |
Output is correct |
7 |
Incorrect |
6 ms |
660 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |