首页 > 其他分享 >CodeForces 1909E Multiple Lamps

CodeForces 1909E Multiple Lamps

时间:2023-12-24 12:23:44浏览次数:34  
标签:const 1280 int 292 Multiple Lamps 1909E 168 256

洛谷传送门

CF 传送门

感觉这个题比较难蚌。

发现按 \(1 \sim n\) 最后可以把 \(1 \sim n\) 中的所有平方数点亮。所以 \(n \ge 20\) 就直接输出 \(1 \sim n\)。

考虑 \(n \le 19\)。猜测合法的方案(即按完后亮灯数 \(\le \left\lfloor\frac{n}{5}\right\rfloor\) 的方案,不考虑 \((u, v)\) 的限制)不会很多。打表发现 \(n = 19\) 时仅有 \(1159\) 种。于是把合法方案预处理出来即可。

赛时智障了,所以直接把表放到代码里了。

code
// Problem: E. Multiple Lamps
// Contest: Codeforces - Pinely Round 3 (Div. 1 + Div. 2)
// URL: https://codeforces.com/contest/1909/problem/E
// Memory Limit: 256 MB
// Time Limit: 3000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
#define lowbit(x) ((x) & (-(x)))
#define pb emplace_back
#define fst first
#define scd second
#define mkp make_pair
#define mems(a, x) memset((a), (x), sizeof(a))

using namespace std;
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<int, int> pii;

const int maxn = 200100;
const int A19[1159] = {16,32,36,64,128,136,168,256,288,292,424,512,528,554,564,576,618,640,648,674,738,768,820,1024,1088,1152,1160,1280,1536,1552,2048,2056,2080,2090,2112,2154,2176,2184,2248,2304,2308,2336,2440,2560,2576,2592,2602,2666,2696,2712,2836,2848,3072,3104,3208,3360,3584,3626,3690,3720,4096,4160,4224,4232,4352,4608,4624,5120,5632,6144,6176,6280,6432,6656,6698,6762,6792,7168,7304,8192,8234,8256,8320,8328,8354,8384,8392,8448,8512,8704,8714,8720,8746,8768,8784,8866,8970,9216,9280,9728,9770,9792,9890,10240,10272,10282,10298,10304,10336,10376,10440,10528,10592,10752,10794,10816,10858,10888,10914,10922,10952,11050,11264,11306,11328,11400,11464,11818,12288,12352,12800,12842,12864,12962,13312,13376,14336,14378,14400,14472,14536,14890,15914,16384,16400,16420,16448,16512,16520,16640,16644,16676,16780,16896,16912,16932,16976,17040,17048,17168,17188,17408,17424,17444,17700,17920,17936,18432,18448,18464,18468,18490,18554,18568,18584,18604,18692,18720,18724,18860,18944,18960,18986,18992,19050,19080,19096,19204,19248,19456,19592,19716,19984,20120,20480,20496,20516,20772,20992,21008,21504,22032,22528,22664,22788,23056,23192,24576,24592,24612,24634,24640,24656,24676,24754,24868,24932,25088,25104,25130,25152,25168,25250,25390,25600,25664,26128,26192,26624,26666,26682,26688,26760,26824,26884,26948,27150,27152,27178,27194,27216,27288,27352,27406,27706,28202,28672,28736,29200,29264,30327,30778,31274,32768,32776,32832,32896,32904,32960,33024,33152,33280,33296,33408,33424,33792,33920,34304,34432,34816,34824,34848,34944,34952,34976,35104,35232,35328,35336,35370,35434,35456,35464,35498,35562,35840,35848,35968,35976,36864,36992,37376,37504,37888,38016,38912,38920,39040,39048,40960,41024,41088,41152,41472,41506,41514,41536,41600,41634,41642,41664,41984,42048,42112,42176,43008,43016,43050,43072,43080,43136,43144,43178,43200,43208,43562,43690,44586,44714,45056,45120,45184,45248,47658,47786,49152,49168,49188,49280,49296,49316,49444,49572,49664,49680,49792,49808,50176,50304,50704,50832,51200,51208,51328,51336,51460,51588,51728,51736,51856,51864,53248,53376,53776,53904,57344,57408,57472,57536,57872,57936,58000,58064,59450,59578,59946,60074,65536,65600,65664,65672,65792,66048,66064,66560,67072,67584,67616,67720,67872,68096,68138,68202,68232,68608,68744,69632,70144,70656,71680,71816,73728,73792,74240,74282,74304,74402,74752,74816,75776,75818,75840,75912,75976,76330,77354,77824,77888,78951,79479,80426,81920,81936,81956,82212,82432,82448,82944,83472,83968,84104,84228,84496,84632,86016,86544,87607,87671,89181,90112,90176,90640,90704,91767,92218,92714,94839,95351,95863,97911,98047,98304,98432,98816,98944,99328,99456,100352,100360,100480,100488,102400,102528,106496,106560,106624,106688,109098,109226,114688,114816,115216,115344,128631,128759,131072,131104,131136,131200,131208,131240,131328,131364,131380,131392,131456,131464,131584,131594,131600,131616,131658,131752,131840,131856,131876,131892,132096,132128,132264,132352,132388,132608,132864,132916,133120,133152,133216,133256,133280,133288,133376,133408,133412,133512,133548,133632,133664,133674,133680,133738,133768,133888,133930,133940,133994,134024,134076,134144,134176,134280,134400,134536,134688,135168,135200,135336,135424,135460,135680,135936,135988,136192,136448,137216,137248,137352,137472,137608,137760,138272,139264,139274,139296,139328,139360,139432,139496,139520,139556,139584,139620,139776,139786,139818,139840,139938,140032,140074,140084,140096,140148,140194,140288,140352,140544,140608,140810,141312,141344,141354,141376,141408,141448,141512,141568,141598,141610,141632,141704,141768,141834,141856,141866,141920,141954,142094,142122,142368,142432,142890,143146,143360,143424,143616,143680,143882,145440,145504,145962,146218,147456,147472,147488,147492,147624,147712,147728,147748,147812,147876,147884,147968,147984,148016,148152,148224,148240,148260,148276,148480,148736,148772,149008,149264,149284,149504,149508,149536,149552,149640,149760,149764,149796,149896,149932,150032,150048,150064,150168,150286,150288,150308,150350,150424,150444,150560,150820,150956,151088,151552,151808,151844,152080,152336,152356,152868,153632,153892,154028,154160,155648,155674,155712,155904,155940,155968,156004,156170,156176,156240,156430,156432,156452,156496,156516,156550,156964,157028,157728,157754,157792,157966,157988,158010,158052,158124,158188,158250,158256,158320,158478,158506,159502,160036,160100,162574,163840,163872,163880,163968,164000,164008,164096,164132,164224,164260,164352,164480,164608,164660,164736,164788,164864,164992,165120,165248,165888,165896,165920,166016,166024,166048,166144,166152,166272,166280,166432,166560,166944,167072,167936,168064,168192,168320,170016,170144,172032,172096,172160,172224,172288,172352,172416,172480,172554,172682,174112,174176,174240,174304,174634,174762,174890,175018,180224,180352,180480,180516,180608,180644,180752,180880,181008,181028,181136,181156,181540,181668,182304,182432,182564,182572,182692,182700,182832,182960,184612,184740,188708,188772,188836,188900,191246,191374,196608,196640,196776,196864,196900,197120,197376,197428,197632,197888,198656,198688,198792,198912,199048,199200,199712,200704,200960,202784,204800,204864,205056,205120,205322,206880,206944,207402,207658,210771,212992,213248,213284,213520,213776,213796,214308,215072,215332,215468,215600,217380,221476,221540,224014,226935,227191,228951,229376,229504,229632,229760,231456,231584,246052,246180,262144,262208,262272,262280,262400,262656,262672,263168,263680,264192,264224,264328,264480,264704,264746,264810,264840,265216,265352,266240,266752,267264,268288,268424,270336,270400,270848,270890,270912,271010,271360,271424,272384,272426,272448,272520,272584,272938,273962,274432,274496,275559,276087,277034,278528,278544,278564,278820,279040,279056,279552,280080,280576,280712,280836,281104,281240,282624,283152,284215,284279,285789,286720,286784,287248,287312,288375,288826,289322,291447,291959,292471,294519,294655,294912,295040,295424,295552,295936,296064,296960,296968,297088,297096,299008,299136,303104,303168,303232,303296,305706,305834,311296,311424,311824,311952,325239,325367,327680,328192,328704,329728,329864,331776,332839,332903,333367,333431,334941,335437,335872,335936,336999,337527,338474,340071,340599,341095,341111,341587,341607,341623,341843,343143,343279,343671,343807,343923,344064,344592,345655,345719,347229,348727,348791,349239,349277,349303,349397,349751,349815,350301,351325,351799,351837,351863,351935,351999,352887,353399,353911,355959,356095,356471,356983,357479,357495,357943,358007,358135,358143,358263,359031,359167,359453,359517,359543,359679,360023,360055,360191,360279,360448,360576,373863,373991,374391,374519,382519,382583,382647,382711,384093,384221,386679,386807,389751,389879,390263,390391,390775,390903,392823,392831,392951,392959,393216,393248,393384,393472,393508,393728,393984,394036,394240,394496,395264,395296,395400,395520,395656,395808,396320,397312,397568,399392,401408,401472,401664,401728,401930,403488,403552,404010,404266,407379,409600,409856,409892,410128,410384,410404,410916,411680,411940,412076,412208,413988,418084,418148,420622,423543,423799,425559,425984,426112,426240,426368,428064,428192,442660,442788,458752,459008,460832,464659,464723,466297,468819,471891,472167,472403,472423,472695,472915,472951,474183,474711,474963,475099,475428,480381,480823,480887,481079,481143,482397,482653,482839,482903,484983,485239,486999,488055,488311,488567,488771,488823,489047,489079,489183,489299,489335,490071,490583,491095,491127,491263,491383,491519,505683,505811,521847,521975,522103,522231,523863,523991};
const int A18[987] = {16,32,36,64,128,136,168,256,288,292,424,512,528,554,564,576,618,640,648,674,738,768,820,1024,1088,1152,1160,1280,1536,1552,2048,2056,2080,2090,2112,2154,2176,2184,2248,2304,2308,2336,2440,2560,2576,2592,2602,2666,2696,2712,2836,2848,3072,3104,3208,3360,3584,3626,3690,3720,4096,4160,4224,4232,4352,4608,4624,5120,5632,6144,6176,6280,6432,6656,6698,6762,6792,7168,7304,8192,8234,8256,8320,8328,8354,8384,8392,8448,8512,8704,8714,8720,8746,8768,8784,8866,8970,9216,9280,9728,9770,9792,9890,10240,10272,10282,10298,10304,10336,10376,10440,10528,10592,10752,10794,10816,10858,10888,10914,10922,10952,11050,11264,11306,11328,11400,11464,11818,12288,12352,12800,12842,12864,12962,13312,13376,13415,13943,14336,14378,14400,14472,14536,14890,15914,16384,16400,16420,16448,16512,16520,16640,16644,16676,16780,16896,16912,16932,16976,17040,17048,17168,17188,17408,17424,17444,17700,17920,17936,18432,18448,18464,18468,18490,18554,18568,18584,18604,18692,18720,18724,18860,18944,18960,18986,18992,19050,19080,19096,19204,19248,19456,19592,19716,19984,20120,20480,20496,20516,20772,20992,21008,21504,22032,22071,22135,22528,22664,22788,23056,23192,23645,24576,24592,24612,24634,24640,24656,24676,24754,24868,24932,25088,25104,25130,25152,25168,25250,25390,25600,25664,26128,26192,26231,26624,26666,26682,26688,26760,26824,26884,26948,27150,27152,27178,27194,27216,27288,27352,27406,27706,28202,28672,28736,29200,29264,29303,29815,30327,30778,31274,32375,32511,32768,32776,32832,32896,32904,32960,33024,33152,33280,33296,33408,33424,33792,33920,34304,34432,34816,34824,34848,34944,34952,34976,35104,35232,35328,35336,35370,35434,35456,35464,35498,35562,35840,35848,35968,35976,36864,36992,37376,37504,37888,38016,38912,38920,39040,39048,40960,41024,41088,41152,41472,41506,41514,41536,41600,41634,41642,41664,41984,42048,42112,42176,43008,43016,43050,43072,43080,43136,43144,43178,43200,43208,43562,43690,44586,44714,45056,45120,45184,45248,47658,47786,49152,49168,49188,49280,49296,49316,49444,49572,49664,49680,49792,49808,50176,50304,50704,50832,51200,51208,51328,51336,51460,51588,51728,51736,51856,51864,53248,53376,53776,53904,57344,57408,57472,57536,57872,57936,58000,58064,59450,59578,59946,60074,63095,63223,65536,65600,65664,65672,65792,66048,66064,66560,67072,67584,67616,67720,67872,68096,68138,68202,68232,68608,68744,69632,70144,70656,70695,70759,71223,71287,71680,71816,72797,73293,73728,73792,74240,74282,74304,74402,74752,74816,74855,75383,75776,75818,75840,75912,75976,76330,77354,77824,77888,77927,78455,78951,78967,79443,79463,79479,79699,80426,80999,81135,81527,81663,81779,81920,81936,81956,82212,82432,82448,82944,83472,83511,83575,83968,84104,84228,84496,84632,85085,86016,86544,86583,86647,87095,87133,87159,87253,87607,87671,88157,89181,89655,89693,89719,89791,89855,90112,90176,90640,90704,90743,91255,91767,92218,92714,93815,93951,94327,94839,95335,95351,95799,95863,95991,95999,96119,96887,97023,97309,97373,97399,97535,97879,97911,98047,98135,98304,98432,98816,98944,99328,99456,100352,100360,100480,100488,102400,102528,106496,106560,106624,106688,109098,109226,111719,111847,112247,112375,114688,114816,115216,115344,120375,120439,120503,120567,121949,122077,124535,124663,127607,127735,128119,128247,128631,128759,130679,130687,130807,130815,131072,131104,131136,131200,131208,131240,131328,131364,131380,131392,131456,131464,131584,131594,131600,131616,131658,131752,131840,131856,131876,131892,132096,132128,132264,132352,132388,132608,132864,132916,133120,133152,133216,133256,133280,133288,133376,133408,133412,133512,133548,133632,133664,133674,133680,133738,133768,133888,133930,133940,133994,134024,134076,134144,134176,134280,134400,134536,134688,135168,135200,135336,135424,135460,135680,135936,135988,136192,136448,137216,137248,137352,137472,137608,137760,138272,139264,139274,139296,139328,139360,139432,139496,139520,139556,139584,139620,139776,139786,139818,139840,139938,140032,140074,140084,140096,140148,140194,140288,140352,140544,140608,140810,141312,141344,141354,141376,141408,141448,141512,141568,141598,141610,141632,141704,141768,141834,141856,141866,141920,141954,142094,142122,142368,142432,142890,143146,143360,143424,143616,143680,143882,145235,145440,145504,145962,146218,147456,147472,147488,147492,147624,147712,147728,147748,147812,147876,147884,147968,147984,148016,148152,148224,148240,148260,148276,148480,148736,148772,149008,149264,149284,149504,149508,149536,149552,149640,149760,149764,149796,149896,149932,150032,150048,150064,150168,150286,150288,150308,150350,150424,150444,150560,150820,150956,151088,151552,151808,151844,152080,152336,152356,152868,153632,153892,154028,154160,155648,155674,155712,155904,155940,155968,156004,156170,156176,156240,156430,156432,156452,156496,156516,156550,156964,157028,157728,157754,157792,157966,157988,158010,158052,158124,158188,158250,158256,158320,158478,158506,159502,160036,160100,161399,161655,162574,163415,163840,163872,163880,163968,164000,164008,164096,164132,164224,164260,164352,164480,164608,164660,164736,164788,164864,164992,165120,165248,165888,165896,165920,166016,166024,166048,166144,166152,166272,166280,166432,166560,166944,167072,167936,168064,168192,168320,170016,170144,172032,172096,172160,172224,172288,172352,172416,172480,172554,172682,174112,174176,174240,174304,174634,174762,174890,175018,180224,180352,180480,180516,180608,180644,180752,180880,181008,181028,181136,181156,181540,181668,182304,182432,182564,182572,182692,182700,182832,182960,184612,184740,188708,188772,188836,188900,191246,191374,196608,196640,196776,196864,196900,197120,197376,197428,197632,197888,198656,198688,198792,198912,199048,199200,199712,200704,200960,202515,202579,202784,204153,204800,204864,205056,205120,205322,206675,206880,206944,207402,207658,209747,210023,210259,210279,210551,210771,210807,212039,212567,212819,212955,212992,213248,213284,213520,213776,213796,214308,215072,215332,215468,215600,217380,218237,218679,218743,218935,218999,220253,220509,220695,220759,221476,221540,222839,223095,224014,224855,225911,226167,226423,226627,226679,226903,226935,227039,227155,227191,227927,228439,228951,228983,229119,229239,229375,229376,229504,229632,229760,231456,231584,243539,243667,246052,246180,259703,259831,259959,260087,261719,261847};
const int A17[833] = {16,32,36,64,128,136,168,256,288,292,308,320,384,392,424,512,522,528,544,554,564,576,586,618,640,648,674,680,738,768,784,804,820,1024,1056,1088,1152,1160,1192,1280,1316,1536,1552,1792,1844,2048,2056,2080,2090,2112,2144,2154,2176,2184,2208,2216,2248,2304,2308,2336,2340,2440,2476,2560,2576,2592,2602,2608,2666,2696,2712,2816,2836,2848,2858,2868,2922,2952,3004,3072,3104,3208,3328,3360,3464,3584,3616,3626,3690,3720,4096,4128,4160,4224,4232,4264,4352,4388,4608,4624,4864,4916,5120,5376,5632,6144,6176,6280,6400,6432,6536,6656,6688,6698,6762,6792,7168,7200,7304,8192,8202,8224,8234,8256,8288,8320,8328,8354,8360,8384,8392,8424,8448,8484,8512,8548,8704,8714,8720,8746,8768,8784,8866,8960,8970,9002,9012,9024,9076,9122,9216,9280,9472,9536,9728,9738,9770,9792,9890,10240,10272,10282,10298,10304,10336,10376,10440,10496,10526,10528,10538,10560,10592,10632,10696,10752,10762,10784,10794,10816,10848,10858,10882,10888,10914,10922,10952,11022,11050,11264,11296,11306,11328,11360,11400,11464,11818,12074,12288,12352,12544,12608,12800,12810,12842,12864,12962,13312,13376,13415,13943,14163,14336,14368,14378,14400,14432,14472,14536,14890,15146,15914,16384,16400,16416,16420,16448,16512,16520,16552,16640,16644,16656,16676,16740,16780,16804,16812,16896,16912,16932,16944,16976,17040,17048,17080,17152,17168,17188,17204,17408,17424,17444,17664,17700,17920,17936,18192,18212,18432,18436,18448,18464,18468,18480,18490,18554,18568,18584,18604,18688,18692,18720,18724,18824,18860,18944,18960,18976,18986,18992,19050,19080,19096,19204,19214,19216,19236,19248,19278,19352,19372,19456,19488,19592,19716,19748,19884,19984,20016,20120,20480,20496,20516,20736,20772,20992,21008,21264,21284,21504,21796,22032,22071,22135,22528,22560,22664,22788,22820,22956,23056,23088,23192,23645,24576,24592,24602,24612,24634,24640,24656,24676,24754,24832,24868,24896,24932,25088,25098,25104,25130,25152,25168,25250,25358,25360,25380,25390,25424,25444,25478,25600,25664,25892,25956,26128,26192,26231,26624,26656,26666,26682,26688,26720,26760,26824,26884,26894,26916,26938,26948,26980,27052,27116,27150,27152,27178,27184,27194,27216,27248,27288,27352,27406,27434,27706,28202,28430,28672,28736,28964,29028,29200,29264,29303,29815,30327,30583,30778,31274,31502,32343,32375,32511,32768,32776,32800,32808,32832,32896,32904,32928,32936,32960,33024,33060,33152,33188,33280,33296,33408,33424,33536,33588,33664,33716,33792,33920,34048,34176,34304,34432,34816,34824,34848,34944,34952,34976,35072,35080,35104,35200,35208,35232,35328,35336,35360,35370,35434,35456,35464,35488,35498,35562,35840,35848,35872,35968,35976,36000,36864,36992,37120,37248,37376,37504,37888,38016,38912,38920,38944,39040,39048,39072,40960,41024,41088,41152,41216,41280,41344,41408,41472,41482,41506,41514,41536,41600,41610,41634,41642,41664,41984,42048,42112,42176,43008,43016,43040,43050,43072,43080,43104,43136,43144,43168,43178,43200,43208,43232,43562,43690,43818,43946,44586,44714,45056,45120,45184,45248,47658,47786,49152,49168,49188,49280,49296,49316,49408,49444,49536,49572,49664,49680,49792,49808,49936,49956,50064,50084,50176,50304,50468,50596,50704,50832,51200,51208,51232,51328,51336,51360,51460,51492,51500,51588,51620,51628,51728,51736,51760,51856,51864,51888,53248,53376,53540,53668,53776,53904,57344,57408,57472,57536,57636,57700,57764,57828,57872,57936,58000,58064,59450,59578,59946,60074,60174,60302,63095,63223,65536,65568,65600,65664,65672,65704,65792,65828,66048,66064,66304,66356,66560,66816,67072,67584,67616,67720,67840,67872,67976,68096,68128,68138,68202,68232,68608,68640,68744,69632,69888,70144,70656,70695,70759,71223,71287,71443,71507,71680,71712,71816,72797,73081,73293,73728,73792,73984,74048,74240,74250,74282,74304,74402,74752,74816,74855,75383,75603,75776,75808,75818,75840,75872,75912,75976,76330,76586,77354,77824,77888,77927,78455,78675,78951,78967,79187,79207,79443,79463,79479,79699,79735,80426,80967,80999,81135,81495,81527,81663,81747,81779,81883,81920,81936,81956,82176,82212,82432,82448,82704,82724,82944,83236,83472,83511,83575,83968,84000,84104,84228,84260,84396,84496,84528,84632,85085,86016,86308,86544,86583,86647,87095,87133,87159,87165,87253,87607,87671,87863,87927,88157,89181,89437,89623,89655,89687,89693,89719,89791,89855,90112,90176,90404,90468,90640,90704,90743,91255,91767,92023,92218,92714,92942,93783,93815,93951,94327,94839,95095,95335,95351,95555,95607,95799,95831,95863,95967,95991,95999,96083,96119,96855,96887,97023,97309,97367,97373,97399,97535,97879,97911,98047,98135,98167,98303,98304,98432,98560,98688,98816,98944,99328,99456,100352,100360,100384,100480,100488,100512,102400,102528,106496,106560,106624,106688,109098,109226,111719,111847,112247,112375,112467,112595,114688,114816,114980,115108,115216,115344,120375,120439,120503,120567,121949,122077,124535,124663,127607,127735,128119,128247,128631,128759,128887,129015,130647,130679,130687,130775,130807,130815};
const int A16[696] = {16,32,36,64,128,136,168,256,288,292,308,320,384,392,424,512,522,528,544,554,564,576,586,618,640,648,674,680,738,768,784,804,820,1024,1056,1088,1152,1160,1192,1280,1316,1536,1552,1792,1844,2048,2056,2080,2090,2112,2144,2154,2176,2184,2208,2216,2248,2304,2308,2336,2340,2440,2476,2560,2576,2592,2602,2608,2666,2696,2712,2816,2836,2848,2858,2868,2922,2952,3004,3072,3104,3208,3328,3360,3464,3584,3616,3626,3690,3720,4096,4128,4160,4224,4232,4264,4352,4388,4608,4624,4864,4916,5120,5159,5223,5376,5632,5687,5751,5907,5971,6144,6176,6280,6400,6432,6536,6656,6688,6698,6762,6792,7168,7200,7261,7304,7545,7757,8192,8202,8224,8234,8256,8288,8320,8328,8354,8360,8384,8392,8424,8448,8484,8512,8548,8704,8714,8720,8746,8768,8784,8866,8960,8970,9002,9012,9024,9076,9122,9216,9280,9319,9472,9536,9728,9738,9770,9792,9847,9890,10067,10240,10272,10282,10298,10304,10336,10376,10440,10496,10526,10528,10538,10560,10592,10632,10696,10752,10762,10784,10794,10816,10848,10858,10882,10888,10914,10922,10952,11022,11050,11264,11296,11306,11328,11360,11400,11464,11818,12074,12288,12352,12391,12544,12608,12800,12810,12842,12864,12919,12962,13139,13312,13376,13415,13431,13651,13671,13907,13927,13943,14163,14199,14336,14368,14378,14400,14432,14472,14536,14890,15146,15431,15463,15599,15914,15959,15991,16127,16211,16243,16347,16384,16400,16416,16420,16448,16512,16520,16552,16640,16644,16656,16676,16740,16780,16804,16812,16896,16912,16932,16944,16976,17040,17048,17080,17152,17168,17188,17204,17408,17424,17444,17664,17700,17920,17936,17975,18039,18192,18212,18432,18436,18448,18464,18468,18480,18490,18554,18568,18584,18604,18688,18692,18720,18724,18824,18860,18944,18960,18976,18986,18992,19050,19080,19096,19204,19214,19216,19236,19248,19278,19352,19372,19456,19488,19549,19592,19716,19748,19884,19984,20016,20120,20480,20496,20516,20736,20772,20992,21008,21047,21111,21264,21284,21504,21559,21597,21623,21629,21717,21796,22032,22071,22135,22327,22391,22528,22560,22621,22664,22788,22820,22956,23056,23088,23192,23645,23901,24087,24119,24151,24157,24183,24255,24319,24576,24592,24602,24612,24634,24640,24656,24676,24754,24832,24868,24896,24932,25088,25098,25104,25130,25152,25168,25207,25250,25358,25360,25380,25390,25424,25444,25478,25600,25664,25719,25892,25956,26128,26192,26231,26487,26624,26656,26666,26682,26688,26720,26760,26824,26884,26894,26916,26938,26948,26980,27052,27116,27150,27152,27178,27184,27194,27216,27248,27288,27352,27406,27434,27706,28202,28247,28279,28415,28430,28672,28736,28791,28964,29028,29200,29264,29303,29559,29799,29815,30019,30071,30263,30295,30327,30431,30455,30463,30547,30583,30778,31274,31319,31351,31487,31502,31773,31831,31837,31863,31999,32343,32375,32511,32599,32631,32767,32768,32776,32800,32808,32832,32896,32904,32928,32936,32960,33024,33060,33152,33188,33280,33296,33408,33424,33536,33588,33664,33716,33792,33920,34048,34176,34304,34432,34816,34824,34848,34944,34952,34976,35072,35080,35104,35200,35208,35232,35328,35336,35360,35370,35434,35456,35464,35488,35498,35562,35840,35848,35872,35968,35976,36000,36864,36992,37120,37248,37376,37504,37888,38016,38912,38920,38944,39040,39048,39072,40960,41024,41088,41152,41216,41280,41344,41408,41472,41482,41506,41514,41536,41600,41610,41634,41642,41664,41984,42048,42112,42176,43008,43016,43040,43050,43072,43080,43104,43136,43144,43168,43178,43200,43208,43232,43562,43690,43818,43946,44586,44714,45056,45120,45184,45248,46183,46311,46711,46839,46931,47059,47658,47786,49152,49168,49188,49280,49296,49316,49408,49444,49536,49572,49664,49680,49792,49808,49936,49956,50064,50084,50176,50304,50468,50596,50704,50832,51200,51208,51232,51328,51336,51360,51460,51492,51500,51588,51620,51628,51728,51736,51760,51856,51864,51888,53248,53376,53540,53668,53776,53904,54839,54903,54967,55031,56413,56541,57344,57408,57472,57536,57636,57700,57764,57828,57872,57936,58000,58064,58999,59127,59450,59578,59946,60074,60174,60302,62071,62199,62583,62711,63095,63223,63351,63479,65111,65143,65151,65239,65271,65279};
const int A15[575] = {8,16,32,36,40,64,128,136,160,168,192,256,288,292,308,320,384,392,420,424,512,522,528,544,554,564,576,586,618,640,648,656,674,680,738,768,784,804,820,896,948,1024,1056,1088,1152,1160,1192,1280,1316,1408,1536,1552,1664,1792,1844,2048,2056,2080,2090,2112,2144,2154,2176,2184,2208,2216,2248,2304,2308,2312,2336,2340,2432,2440,2464,2476,2560,2568,2576,2592,2602,2608,2666,2688,2696,2712,2720,2730,2794,2816,2836,2848,2858,2868,2922,2952,3004,3072,3080,3104,3200,3208,3232,3328,3360,3464,3584,3616,3626,3690,3720,4096,4128,4160,4224,4232,4264,4352,4388,4480,4608,4624,4736,4864,4916,5120,5159,5223,5248,5376,5632,5687,5751,5907,5971,6144,6152,6176,6272,6280,6304,6400,6432,6536,6656,6688,6698,6762,6792,7168,7200,7261,7304,7545,7757,8192,8202,8224,8234,8256,8288,8320,8328,8354,8360,8384,8392,8424,8448,8484,8512,8548,8576,8640,8704,8714,8720,8738,8746,8768,8784,8832,8842,8866,8874,8896,8960,8970,9002,9012,9024,9076,9122,9216,9280,9319,9344,9408,9472,9536,9728,9738,9770,9792,9847,9890,10067,10240,10248,10272,10282,10298,10304,10312,10336,10368,10376,10400,10410,10432,10440,10464,10496,10526,10528,10538,10560,10592,10632,10696,10752,10762,10784,10794,10816,10848,10858,10882,10888,10914,10922,10952,11022,11050,11178,11264,11296,11306,11328,11360,11400,11464,11818,11946,12074,12288,12352,12391,12416,12480,12544,12608,12800,12810,12842,12864,12919,12962,13139,13312,13376,13415,13431,13543,13651,13671,13907,13927,13943,14071,14163,14199,14291,14336,14368,14378,14400,14432,14472,14536,14890,15018,15146,15431,15463,15599,15914,15959,15991,16127,16211,16243,16347,16384,16400,16416,16420,16448,16512,16520,16528,16548,16552,16640,16644,16656,16676,16740,16768,16780,16804,16812,16896,16912,16932,16944,16976,17024,17040,17048,17080,17152,17168,17188,17204,17296,17316,17408,17424,17444,17536,17664,17700,17828,17920,17936,17975,18039,18064,18192,18212,18432,18436,18440,18448,18464,18468,18480,18490,18554,18560,18568,18584,18592,18604,18688,18692,18720,18724,18732,18820,18824,18852,18860,18944,18960,18968,18976,18986,18992,19050,19080,19088,19096,19120,19204,19214,19216,19236,19248,19278,19352,19372,19456,19488,19549,19592,19716,19748,19884,19984,20016,20120,20480,20496,20516,20608,20736,20772,20900,20992,21008,21047,21111,21136,21264,21284,21504,21559,21597,21623,21629,21717,21796,22032,22071,22135,22199,22263,22327,22391,22528,22560,22621,22664,22788,22820,22956,23056,23088,23192,23645,23773,23901,24087,24119,24151,24157,24183,24255,24319,24576,24592,24602,24612,24634,24640,24656,24676,24704,24754,24768,24832,24868,24896,24932,24996,25060,25088,25098,25104,25130,25152,25168,25207,25232,25250,25296,25358,25360,25380,25390,25424,25444,25478,25600,25664,25719,25892,25956,26128,26192,26231,26359,26487,26624,26656,26666,26682,26688,26720,26760,26810,26824,26884,26894,26916,26938,26948,26980,27052,27116,27150,27152,27178,27184,27194,27216,27248,27288,27306,27352,27406,27434,27534,27706,28202,28247,28279,28415,28430,28672,28736,28791,28964,29028,29200,29264,29303,29431,29559,29799,29815,29943,30019,30071,30263,30295,30327,30431,30455,30463,30547,30583,30711,30778,31274,31319,31351,31487,31502,31773,31831,31837,31863,31999,32343,32375,32383,32471,32503,32511,32599,32631,32767};
const int A14[105] = {16,32,36,64,128,136,168,256,292,384,420,512,528,640,656,768,784,804,820,1024,1152,1280,1316,1536,1552,2048,2056,2080,2176,2184,2208,2304,2308,2336,2340,2440,2476,2560,2576,2592,2602,2608,2666,2696,2712,3072,3104,3208,4096,4224,4352,4388,4608,4624,5120,5687,5751,6144,6176,6280,7261,8192,8256,8320,8384,8448,8484,8512,8548,8704,8714,8720,8746,8768,8784,8866,9216,9280,9847,10240,10272,10282,10298,10304,10336,10376,10440,10794,10922,11022,11050,11818,12288,12352,12919,13415,13431,13943,14071,14163,14199,14890,15959,15991,16127};
const int A13[91] = {16,32,36,64,128,136,168,192,256,292,320,356,384,420,512,522,528,554,576,592,640,656,674,768,784,804,820,1024,1088,1152,1280,1316,1536,1552,1655,2048,2056,2080,2090,2106,2112,2144,2176,2184,2208,2248,2304,2308,2336,2340,2440,2476,2560,2576,2592,2602,2608,2666,2696,2712,2730,2830,2858,3072,3104,3208,3626,4096,4160,4224,4352,4388,4608,4624,4727,5120,5223,5239,5687,5751,5879,5971,6007,6144,6176,6280,6698,7261,7767,7799,7935};
const int A12[78] = {16,32,36,64,128,136,168,192,256,292,320,356,384,420,512,522,528,554,576,592,631,640,656,674,768,784,804,820,1024,1088,1127,1143,1152,1280,1316,1536,1552,1591,1655,1783,1875,1911,2048,2056,2080,2090,2106,2112,2144,2176,2184,2208,2248,2304,2308,2336,2340,2440,2476,2560,2576,2592,2602,2608,2666,2696,2712,2730,2830,2858,3072,3104,3165,3208,3626,3671,3703,3839};
const int A11[66] = {8,16,32,36,42,58,64,96,128,136,160,168,192,200,256,260,288,292,320,356,384,392,420,428,512,522,528,544,554,560,576,592,618,631,640,648,656,664,674,682,768,782,784,804,810,820,1024,1056,1088,1117,1127,1143,1152,1160,1280,1316,1536,1552,1578,1591,1623,1655,1783,1791,1875,1911};

int n, m, to[maxn], f[9999];

inline bool check(int S) {
	for (int i = 0; i < n; ++i) {
		if ((S & (1 << i)) && (S & to[i]) != to[i]) {
			return 0;
		}
	}
	return 1;
}

inline void print(int S) {
	printf("%d\n", __builtin_popcount(S));
	for (int i = 0; i < n; ++i) {
		if (S & (1 << i)) {
			printf("%d ", i + 1);
		}
	}
	putchar('\n');
}

void solve() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; ++i) {
		to[i] = 0;
	}
	while (m--) {
		int u, v;
		scanf("%d%d", &u, &v);
		--u;
		--v;
		if (n < 20) {
			to[u] |= (1 << v);
		}
	}
	if (n >= 20) {
		printf("%d\n", n);
		for (int i = 1; i <= n; ++i) {
			printf("%d ", i);
		}
		putchar('\n');
		return;
	}
	if (n <= 10) {
		for (int i = 0; i < (1 << n); ++i) {
			f[i] = 0;
		}
		for (int S = 1; S < (1 << n); ++S) {
			int i = __lg(lowbit(S)) + 1, &t = f[S] = f[S ^ (1 << (i - 1))];
			for (int j = i; j <= n; j += i) {
				t ^= (1 << j);
			}
		}
		for (int S = 1; S < (1 << n); ++S) {
			if (__builtin_popcount(f[S]) <= n / 5 && check(S)) {
				print(S);
				return;
			}
		}
		puts("-1");
		return;
	}
	if (n == 11) {
		for (int i = 0; i < 66; ++i) {
			int S = A11[i];
			if (check(S)) {
				print(S);
				return;
			}
		}
		puts("-1");
		return;
	}
	if (n == 12) {
		for (int i = 0; i < 78; ++i) {
			int S = A12[i];
			if (check(S)) {
				print(S);
				return;
			}
		}
		puts("-1");
		return;
	}
	if (n == 13) {
		for (int i = 0; i < 91; ++i) {
			int S = A13[i];
			if (check(S)) {
				print(S);
				return;
			}
		}
		puts("-1");
		return;
	}
	if (n == 14) {
		for (int i = 0; i < 105; ++i) {
			int S = A14[i];
			if (check(S)) {
				print(S);
				return;
			}
		}
		puts("-1");
		return;
	}
	if (n == 15) {
		for (int i = 0; i < 575; ++i) {
			int S = A15[i];
			if (check(S)) {
				print(S);
				return;
			}
		}
		puts("-1");
		return;
	}
	if (n == 16) {
		for (int i = 0; i < 696; ++i) {
			int S = A16[i];
			if (check(S)) {
				print(S);
				return;
			}
		}
		puts("-1");
		return;
	}
	if (n == 17) {
		for (int i = 0; i < 833; ++i) {
			int S = A17[i];
			if (check(S)) {
				print(S);
				return;
			}
		}
		puts("-1");
		return;
	}
	if (n == 18) {
		for (int i = 0; i < 987; ++i) {
			int S = A18[i];
			if (check(S)) {
				print(S);
				return;
			}
		}
		puts("-1");
		return;
	}
	if (n == 19) {
		for (int i = 0; i < 1159; ++i) {
			int S = A19[i];
			if (check(S)) {
				print(S);
				return;
			}
		}
		puts("-1");
		return;
	}
}

int main() {
	int T = 1;
	scanf("%d", &T);
	while (T--) {
		solve();
	}
	return 0;
}

标签:const,1280,int,292,Multiple,Lamps,1909E,168,256
From: https://www.cnblogs.com/zltzlt-blog/p/17924231.html

相关文章

  • 【JAVA】Multiple markers at this line @Override的解决方法
    【未解决】我的是1.8,都显示的是1.8使用Eclipse进行项目开发,在实现类中的方法前面如果添加@Override就提示“Multiplemarkersatthisline”的错误,问题描述如下Multiplemarkersatthisline-ThemethodgetStudentByID(String)oftypeStudentBeanImplmustoverridea......
  • ARC166 B Make Multiples 题解
    LinkARC166BMakeMultiplesQuestion给出\(N\)个整数,\(A_1...A_N\),还有三个数\(a,b,c\)我们可以给\(A_i\)加上\(1\)需要使得数组\(A\)满足,存在一个数是\(a\)的倍数,一个数是\(b\)的倍数,一个数是\(c\)的倍数求最少的操作次数Solution考虑对于每个数的操作......
  • Dependency injection framework -- Decoupled packages example (multiple container
    Dependencyinjectionframeworkhttps://python-dependency-injector.ets-labs.org/index.htmlDependencyInjectorisadependencyinjectionframeworkforPython.Ithelpsimplementingthedependencyinjectionprinciple.KeyfeaturesoftheDependencyInjecto......
  • Unsourced Multiple Access With Random User Activity论文复现
    仿真内容文件中包含了一个关于无源多用户接入(UnsourcedMultipleAccess,UMA)系统的MATLAB数值例程,用于评估随机用户活动情况下的随机编码界限。这个工作主要在论文[1]中介绍,该论文题为"UnsourcedMultipleAccessWithRandomUserActivity",于2022年1月提交给IEEET......
  • KEILC51编译问题ERROR L104: MULTIPLE PUBLIC DEFINITIONS重复定义
    这个问题是keil中比较常见的,但对于很多新手比较头疼的像出现这种104的报错 出现上述错误则是因为函数Delay_ms重复定义,我们只需要把这个函数名改一个就OK了 我们可以把.c.h文件的Delay_ms改为Delay1_ms,在调用函数也改为Delay1_ms,然后编译就不会出错了。 ......
  • multipleWindow3dScene代码解释
    title:深入分析:GitHubTrending项目"multipleWindow3dScene"banner_img:https://cdn.studyinglover.com/pic/2023/11/b57a22bd9cf8a1c0a954fd61e6c311f2.pngdate:2023-11-2719:18:00tags:-文字生成图片这是由chatGPT生成的文章,内容是关于GitHubTrending项目"multi......
  • Dapper QueryMultiple throws "No columns were selected"
    调试存储过程发现某字段NULL,拼成的SQL最后啥也没有了。。。原因是存储过程没有执行到查询SQL语句QueryAsyncthrows"Nocolumnswereselected"whenstoredprocdoesn'tperformaselectstatement #591Closed  toannguyen83 openedthisissue onAug27,20......
  • 神经网络入门篇:详解多样本向量化(Vectorizing across multiple examples)
    多样本向量化与上篇博客相联系的来理解逻辑回归是将各个训练样本组合成矩阵,对矩阵的各列进行计算。神经网络是通过对逻辑回归中的等式简单的变形,让神经网络计算出输出值。这种计算是所有的训练样本同时进行的,以下是实现它具体的步骤:图1.4.1上篇博客中得到的四个等式。它们......
  • Displaying multiple columns in a HTML Listbox Control in ASP.Net
    REF:http://forums.aspfree.com/net-development-11/displaying-multiple-columns-in-a-html-listbos-control-in-asp-19062.html listboxcolumnspacingsolutionFINALLY!!!IKnowsomanypeoplehavehadthisproblem.Butfinallyisolveditwithyourbasicmonos......
  • Tmux终端复用器(terminal multiplexer)使用教程
    Tmux基础用法会话与进程¶命令行的典型用法是打开终端(terminal)后,在里面输入指令。用户的这种与计算机交互的手段,称为会话(session)。在会话中,通过命令行启动的所有进程均与会话进程绑定。当会话进程终止时,该会话启动的所有进程也会随之强行结束。一点最常见的例子就是通过SSH连......