#P6161. [Cnoi2020] 高维
[Cnoi2020] 高维
Background
In essence, Gensokyo is high-dimensional.
Problem Description
Cirno has caught an -dimensional ant. It wants to crawl from to .
Trapped inside this grid, the ant can move in each step only to a point adjacent in exactly one coordinate.
Now Cirno wants to test you: what is the maximum number of pairwise vertex-disjoint paths from to (excluding and ) that the ant can find?
You are also required to construct such a set of paths.
Input Format
One line with one integer .
Output Format
The first line contains one integer , the maximum number of paths.
The next lines each contain one valid path.
A valid path is written as:
[space] [space] [space] ... [space]
where is a binary-compressed string representing an -dimensional coordinate.
Do not output extra spaces.
2
2
0 1 3
0 2 3
Hint
"This problem uses Special Judge."
Explanation of Sample 1
Path : .
Path : .
They have no common points except and .
Constraints
"This problem does not use bundled testdata; the testdata has multiple difficulty levels."
For 100% of the testdata, .
Attached Code Snippets
- Binary packing function
/**
* For only cpp11, cpp14, cpp17, cpp20.
*
* @param: __s : The binary high-dimension position inputed.
* @return: Standard output format( U64 ).
**/
unsigned long long zip( std::string __s )
{ unsigned long long __r = 0;
for( auto __c : __s )
{ ( __r <<= 1ull ) |= ( __c - 0x30 ); }
return __r; }
- SPJ code
//SPJ
#include "testlib.h"
#include<bits/stdc++.h>
typedef unsigned long long ULL;
typedef std::vector<std::string> SEQ;
typedef std::string STR;
SEQ split( std::string _par, char _sgn )
{ SEQ _rat = SEQ();
STR _rem = STR();
for( char __c : _par )
{ if( __c = _sgn ) _rat.push_back( _rem ), _rem = "";
else _rem += __c; }
if( _rem != "" ) _rat.push_back( _rem );
return _rat; }
ULL to_ULL( std::string _str )
{ ULL _rat = 0;
for( char __c : _str )
{ ( _rat *= 10ull ) += (ULL)( __c - '0' ); }
return _rat; }
bool isPw2( ULL x )
{ return !( x & (x - 1ull) ); }
std::map<ULL, bool> MP;
int main(int argc, char* argv[]) {
registerTestlibCmd(argc, argv);
ULL n = inf.readLong();
ULL S = 0, T = (1ull << n) - 1ull;
ULL N = ouf.readLong();
if( N != n ) quitf( _wa, "Count paths wrongly." );
ouf.readEoln();
while( n -- ) {
std::string path = ouf.readLine();
ULL _lst = 0;
for( auto N : split( path, " " ) )
{ ULL _now = to_ULL( N );
if( _now != S and _now != T and MP[_now] )
{ quitf( _wa, "Paths crossing" ); }
if( !isPw2( _now ^ _lst ) )
{ quitf( _wa, "Wrong path format" ); }
_lst = _now; MP[_now] = true; }
if( _lst != T ) quitf( _wa, "Wrong path ending" );
}
quitf( _ok, "Accepted" );
return 0;
}
Translated by ChatGPT 5