QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#125566 | #6317. XOR Tree Path | Energy_is_not_over# | RE | 0ms | 0kb | C++17 | 5.0kb | 2023-07-16 21:38:15 | 2023-07-16 21:38:17 |
Judging History
answer
//#pragma GCC optimize("Ofast", "unroll-loops")
//#pragma GCC target("sse", "sse2", "sse3", "ssse3", "sse4")
#ifdef __APPLE__
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <cstdint>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <random>
#include <deque>
#include <functional>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <complex>
#include <numeric>
#include <cassert>
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <thread>
#else
#include <bits/stdc++.h>
#endif
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
template<typename T>
bool umin(T &a, T b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template<typename T>
bool umax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
#if __APPLE__
#define D for (bool _FLAG = true; _FLAG; _FLAG = false)
#define LOG(...) print(#__VA_ARGS__" ::", __VA_ARGS__) << endl
template <class ...Ts> auto &print(Ts ...ts) { return ((cerr << ts << " "), ...); }
#else
#define D while (false)
#define LOG(...)
#endif
const int max_n = -1, inf = 1000111222;
struct one_move
{
int a,b;
};
struct four_moves
{
one_move moves[4];
};
const int N=16;
struct state
{
int l[N+1];
vector<four_moves> moves;
bool is_ok(int p)
{
for (int i=1;i<=p;i++){
if (l[i]!=1){
return false;
}
}
return true;
}
};
bool cmp1(const state& lhs,const state& rhs)
{
for (int i=1;i<=N;i++){
if (lhs.l[i]!=rhs.l[i]){
return lhs.l[i]<rhs.l[i];
}
}
return 0;
}
int f(const state& a)
{
int res=0;
for (int i=1;i<=N;i++){
res+=a.l[i];
}
return res;
}
bool cmp2(const state& lhs,const state& rhs)
{
return f(lhs)<f(rhs);
}
state start;
state answer[17];
int main() {
// freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
for (int i=1;i<=N;i++){
start.l[i]=i;
}
const int max_states=10000;
vector<state> s;
s.pb(start);
for (int i=0;i<10;i++){
LOG("on dist ",i);
// D{
// for (auto i:s){
// cerr<<"{";
// for (int j=1;j<=N;j++){
// cerr<<i.l[j]<<",";
// }
// cerr<<"}";
// cerr<<"\n";
// }
// };
LOG("len of s is ",len(s));
vector<state> new_s;
for (auto j:s){
for (int k=1;k<=N;k++){
if (answer[k].l[1]==0 && j.is_ok(k)){
answer[k]=j;
LOG("found answer",k,i);
if (k==N){
goto finish;
}
}
}
#define f(a,start) for (int a=start;a<=N;a++)
f(i1,1)
f(i2,i1)
f(i3,i2)
f(i4,i3){
state new_state=j;
four_moves cur_moves;
cur_moves.moves[0]=one_move{j.l[i1]==1 ? -1 : j.l[i1]-1,i1};
cur_moves.moves[1]=one_move{j.l[i2]==1 ? -1 : j.l[i2]-1,i2};
cur_moves.moves[2]=one_move{j.l[i3]==1 ? -1 : j.l[i3]-1,i3};
cur_moves.moves[3]=one_move{j.l[i4]==1 ? -1 : j.l[i4]-1,i4};
new_state.moves.pb(cur_moves);
if (j.l[i1]!=1)
new_state.l[i1]=j.l[j.l[i1]-1];
if (j.l[i2]!=1)
new_state.l[i2]=j.l[j.l[i2]-1];
if (j.l[i3]!=1)
new_state.l[i3]=j.l[j.l[i3]-1];
if (j.l[i4]!=1)
new_state.l[i4]=j.l[j.l[i4]-1];
new_s.pb(new_state);
}
}
s=new_s;
sort(all(s),cmp1);
vector<state> new_s_s;
for (auto i:s){
if (new_s_s.empty() || (cmp1(i,new_s_s.back()) || !cmp1(i,new_s_s.back()))){
new_s_s.pb(i);
}
}
s=new_s_s;
sort(all(s),cmp2);
if (len(s)>max_states){
s.resize(max_states);
}
}
finish:;
for (int i=1;i<=N;i++){
cout<<answer[i].moves.size()<<" ";
for (auto j:answer[i].moves){
for (int k=0;k<4;k++){
cout<<j.moves[k].a<<" "<<j.moves[k].b<<" ";
}
}
}
}
详细
Test #1:
score: 0
Dangerous Syscalls
input:
5 1 0 0 1 0 1 2 1 3 3 4 3 5