QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#736259 | #2134. Balanced Illumination | N_z_ | AC ✓ | 4ms | 4008kb | C++23 | 7.1kb | 2024-11-12 08:45:29 | 2024-11-12 08:45:30 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
struct time_helper{
#ifdef LOCAL
clock_t time_last;time_helper(){time_last=clock();}void test(){auto time_now=clock();std::cerr<<"time:"<<1.*(time_now-time_last)/CLOCKS_PER_SEC<<";all_time:"<<1.*time_now/CLOCKS_PER_SEC<<std::endl;time_last=time_now;}~time_helper(){test();}
#else
void test(){}
#endif
}time_helper;
#ifdef LOCAL
#include"dbg.h"
#else
#define dbg(...) (__VA_ARGS__)
#endif
namespace Fread{const int SIZE=1<<16;char buf[SIZE],*S,*T;inline char getchar(){if(S==T){T=(S=buf)+fread(buf,1,SIZE,stdin);if(S==T)return'\n';}return *S++;}}namespace Fwrite{const int SIZE=1<<16;char buf[SIZE],*S=buf,*T=buf+SIZE;inline void flush(){fwrite(buf,1,S-buf,stdout);S=buf;}inline void putchar(char c){*S++=c;if(S==T)flush();}struct NTR{~NTR(){flush();}}ztr;}
#define getchar Fread::getchar
#define putchar Fwrite::putchar
int print_precision=10;bool print_T_endl=1;char print_between=' ';
template<typename T>struct is_char{static constexpr bool value=(std::is_same<T,char>::value||std::is_same<T,signed char>::value||std::is_same<T,unsigned char>::value);};template<typename T>struct is_integral_ex{static constexpr bool value=(std::is_integral<T>::value||std::is_same<T,__int128>::value)&&!is_char<T>::value;};template<typename T>struct is_floating_point_ex{static constexpr bool value=std::is_floating_point<T>::value||std::is_same<T,__float128>::value;};namespace Fastio{struct Reader;struct Writer;template<size_t id>struct read_tuple{template<typename...T>static void read(Reader&stream,std::tuple<T...>&x){read_tuple<id-1>::read(stream,x);stream>>get<id-1>(x);}};template<>struct read_tuple<0>{template<typename...T>static void read([[maybe_unused]]Reader&stream,[[maybe_unused]]std::tuple<T...>&x){}};template<size_t id>struct print_tuple{template<typename...T>static void print(Writer&stream,const std::tuple<T...>&x){print_tuple<id-1>::print(stream,x);putchar(print_between);stream<<get<id-1>(x);}};template<>struct print_tuple<1>{template<typename...T>static void print(Writer&stream,const std::tuple<T...>&x){stream<<get<0>(x);}};template<>struct print_tuple<0>{template<typename...T>static void print([[maybe_unused]]Writer&stream,[[maybe_unused]]const std::tuple<T...>&x){}};
struct Reader{template<typename T>typename std::enable_if_t<std::is_class<T>::value,Reader&>operator>>(T&x){for(auto &y:x)*this>>y;return *this;}template<typename...T>Reader&operator>>(std::tuple<T...>&x){read_tuple<sizeof...(T)>::read(*this,x);return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1;while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}x=0;while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}x*=f;return *this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1,s=0;x=0;T t=0;while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else return x*=f,*this;while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Reader&>operator>>(T&c){c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();return *this;}Reader&operator>>(char*str){int len=0;char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str[len++]=c,c=getchar();str[len]='\0';return*this;}template<typename T1,typename T2>Reader&operator>>(std::pair<T1,T2>&x){*this>>x.first>>x.second;return *this;}Reader&operator>>(std::string&str){str.clear();char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str.push_back(c),c=getchar();return*this;}Reader(){}}cin;const char endl='\n';
struct Writer{typedef __int128 mxdouble;template<typename T>typename std::enable_if_t<std::is_class<T>::value,Writer&>operator<<(const T&x){for(auto q:x){*this<<q;if(!is_class<decltype(q)>::value)*this<<print_between;}if(!is_class<typename T::value_type>::value&&print_T_endl)*this<<'\n';return *this;}template<typename...T>Writer&operator<<(const std::tuple<T...>&x){print_tuple<sizeof...(T)>::print(*this,x);if(print_T_endl)*this<<'\n';return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Writer&>operator<<(T x){if(x==0)return putchar('0'),*this;if(x<0)putchar('-'),x=-x;static int sta[45];int top=0;while(x)sta[++top]=x%10,x/=10;while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Writer&>operator<<(T x){if(x<0)putchar('-'),x=-x;x+=pow(10,-print_precision)/2;mxdouble _=x;x-=(T)_;static int sta[45];int top=0;while(_)sta[++top]=_%10,_/=10;if(!top)putchar('0');while(top)putchar(sta[top]+'0'),--top;putchar('.');for(int i=0;i<print_precision;i++)x*=10;_=x;while(_)sta[++top]=_%10,_/=10;for(int i=0;i<print_precision-top;i++)putchar('0');while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Writer&>operator<<(const T&c){putchar(c);return*this;}Writer&operator<<(char*str){int cur=0;while(str[cur])putchar(str[cur++]);return *this;}Writer&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}template<typename T1,typename T2>Writer&operator<<(const std::pair<T1,T2>&x){*this<<x.first<<print_between<<x.second;if(print_T_endl)*this<<'\n';return *this;}Writer&operator<<(const std::string&str){int st=0,ed=str.size();while(st<ed)putchar(str[st++]);return*this;}Writer(){}}cout;}
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl
template<class Fun>class y_combinator_result{Fun fun_;public:template<class T>explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}template<class ...Args>decltype(auto) operator()(Args &&...args){return fun_(std::ref(*this), std::forward<Args>(args)...);}};template<class Fun>decltype(auto) y_combinator(Fun &&fun){return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));}
void init();void solve(int tc);
main()
{
init();int t=1;
// cin>>t;
for(int tc=1;tc<=t;tc++)solve(tc);
}
void init()
{
}
vector<int>work(int n)
{
if(n==1)return {0,0};
if(n==2)return {0,1,0,1};
if(n==3)return {1,0,2,0,1,0,2,0};
vector<int>sres=work(n-2);
int u=(1<<n-1)/n,v=(1<<n-1)%n;
if(v>=2)v-=2;
vector<int>cnt(n-2);
for(auto q:sres)cnt[q]++;
cnt[sres.back()]--;
for(int x=0;x<n-2;x++)
cnt[x]=cnt[x]*2-u-(x<v);
vector<int>ful(1<<n-2),res;
for(int x=0;x<(1<<n-2)-1;x++)
if(cnt[sres[x]])cnt[sres[x]]--,ful[x]=1;
ful.back()=1;
for(int l=0,r,now=0;l<1<<n-2;l=r+1)
{
r=l;
while(!ful[r])r++;
for(int x=l;x<r;x++)res.emplace_back(sres[x]);
res.emplace_back(n-1-now);
for(int x=r-1;x>=l;x--)res.emplace_back(sres[x]);
now=!now,res.emplace_back(n-1-now);
for(int x=l;x<r;x++)res.emplace_back(sres[x]);
res.emplace_back(sres[r]);
}
res.back()=n-1;
for(int x=(1<<n-2)-2;x>=0;x--)
res.emplace_back(sres[x]);
res.emplace_back(n-2);
return res;
}
void solve([[maybe_unused]]int tc)
{
int n;
cin>>n;
string a(n,'0');
for(auto q:work(n))a[q]^=1,cout<<a<<endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3620kb
input:
3
output:
010 110 111 011 001 101 100 000
result:
ok n = 3, mihch = 2, maxch = 4
Test #2:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
4
output:
0001 0011 1011 1111 1101 1001 1000 1100 0100 0101 0111 0110 1110 1010 0010 0000
result:
ok n = 4, mihch = 4, maxch = 4
Test #3:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
1
output:
1 0
result:
ok n = 1, mihch = 2, maxch = 2
Test #4:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
2
output:
10 11 01 00
result:
ok n = 2, mihch = 2, maxch = 2
Test #5:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
5
output:
00001 00011 01011 01001 01000 11000 11001 11011 11111 11101 11100 01100 00100 10100 10000 10001 10101 00101 01101 01111 00111 10111 10011 10010 10110 00110 01110 11110 11010 01010 00010 00000
result:
ok n = 5, mihch = 6, maxch = 8
Test #6:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
6
output:
000001 000011 000111 000101 000100 001100 001101 001111 101111 101101 101100 111100 110100 110101 111101 111111 110111 100111 100101 100100 100000 100001 100011 110011 110001 110000 010000 010001 010011 010111 011111 011011 011001 011101 010101 010100 011100 011000 111000 101000 001000 001001 101001...
result:
ok n = 6, mihch = 10, maxch = 12
Test #7:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
7
output:
0000001 0000011 0000111 0000101 0000100 0001100 0001101 0001111 0101111 0100111 0100101 0101101 0101100 0100100 0100000 0100001 0100011 1100011 1100001 1100000 1100100 1101100 1101101 1100101 1100111 1101111 1111111 1110111 1110011 1110001 1110101 1111101 1111100 1110100 1110000 0110000 0110001 0110...
result:
ok n = 7, mihch = 18, maxch = 20
Test #8:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
8
output:
00000001 00000011 00000111 00000101 00000100 00001100 00001101 00001111 00011111 00011101 00011100 00010100 00010101 00010111 00010011 00010001 00010000 00110000 00110001 00110011 00110111 00110101 00110100 00111100 00111101 00111111 10111111 10111101 10111100 10110100 10110101 10110111 10110011 101...
result:
ok n = 8, mihch = 32, maxch = 32
Test #9:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
9
output:
000000001 000000011 000000111 000000101 000000100 000001100 000001101 000001111 000011111 000011101 000011100 000010100 000010101 000010111 000010011 000010001 000010000 000110000 000110001 000110011 000110111 000110101 000110100 000111100 000111101 000111111 010111111 010111101 010111100 010011100 ...
result:
ok n = 9, mihch = 56, maxch = 58
Test #10:
score: 0
Accepted
time: 0ms
memory: 3660kb
input:
10
output:
0000000001 0000000011 0000000111 0000000101 0000000100 0000001100 0000001101 0000001111 0000011111 0000011101 0000011100 0000010100 0000010101 0000010111 0000010011 0000010001 0000010000 0000110000 0000110001 0000110011 0000110111 0000110101 0000110100 0000111100 0000111101 0000111111 0001111111 000...
result:
ok n = 10, mihch = 102, maxch = 104
Test #11:
score: 0
Accepted
time: 0ms
memory: 3888kb
input:
11
output:
00000000001 00000000011 00000000111 00000000101 00000000100 00000001100 00000001101 00000001111 00000011111 00000011101 00000011100 00000010100 00000010101 00000010111 00000010011 00000010001 00000010000 00000110000 00000110001 00000110011 00000110111 00000110101 00000110100 00000111100 00000111101 ...
result:
ok n = 11, mihch = 186, maxch = 188
Test #12:
score: 0
Accepted
time: 1ms
memory: 3640kb
input:
12
output:
000000000001 000000000011 000000000111 000000000101 000000000100 000000001100 000000001101 000000001111 000000011111 000000011101 000000011100 000000010100 000000010101 000000010111 000000010011 000000010001 000000010000 000000110000 000000110001 000000110011 000000110111 000000110101 000000110100 0...
result:
ok n = 12, mihch = 340, maxch = 342
Test #13:
score: 0
Accepted
time: 1ms
memory: 4008kb
input:
13
output:
0000000000001 0000000000011 0000000000111 0000000000101 0000000000100 0000000001100 0000000001101 0000000001111 0000000011111 0000000011101 0000000011100 0000000010100 0000000010101 0000000010111 0000000010011 0000000010001 0000000010000 0000000110000 0000000110001 0000000110011 0000000110111 000000...
result:
ok n = 13, mihch = 630, maxch = 632
Test #14:
score: 0
Accepted
time: 1ms
memory: 3752kb
input:
14
output:
00000000000001 00000000000011 00000000000111 00000000000101 00000000000100 00000000001100 00000000001101 00000000001111 00000000011111 00000000011101 00000000011100 00000000010100 00000000010101 00000000010111 00000000010011 00000000010001 00000000010000 00000000110000 00000000110001 00000000110011 ...
result:
ok n = 14, mihch = 1170, maxch = 1172
Test #15:
score: 0
Accepted
time: 2ms
memory: 3688kb
input:
15
output:
000000000000001 000000000000011 000000000000111 000000000000101 000000000000100 000000000001100 000000000001101 000000000001111 000000000011111 000000000011101 000000000011100 000000000010100 000000000010101 000000000010111 000000000010011 000000000010001 000000000010000 000000000110000 000000000110...
result:
ok n = 15, mihch = 2184, maxch = 2186
Test #16:
score: 0
Accepted
time: 4ms
memory: 3844kb
input:
16
output:
0000000000000001 0000000000000011 0000000000000111 0000000000000101 0000000000000100 0000000000001100 0000000000001101 0000000000001111 0000000000011111 0000000000011101 0000000000011100 0000000000010100 0000000000010101 0000000000010111 0000000000010011 0000000000010001 0000000000010000 00000000001...
result:
ok n = 16, mihch = 4096, maxch = 4096
Test #17:
score: 0
Accepted
time: 0ms
memory: 3912kb
input:
17
output:
00000000000000001 00000000000000011 00000000000000111 00000000000000101 00000000000000100 00000000000001100 00000000000001101 00000000000001111 00000000000011111 00000000000011101 00000000000011100 00000000000010100 00000000000010101 00000000000010111 00000000000010011 00000000000010001 000000000000...
result:
ok n = 17, mihch = 7710, maxch = 7712