This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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);
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |