QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#882117#2707. Weird Numeral Systemsdds8 4ms31124kbC++141.4kb2025-02-04 21:12:352025-02-04 21:12:36

Judging History

This is the latest submission verdict.

  • [2025-02-04 21:12:36]
  • Judged
  • Verdict: 8
  • Time: 4ms
  • Memory: 31124kb
  • [2025-02-04 21:12:35]
  • Submitted

answer

#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <vector>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <bitset>

#define ll long long
#define maxn 1000007

using namespace std;

__int128 K , q , D , M , x , ans , N , a[maxn] , f[maxn]; vector< __int128 >v[maxn];

bool F[100][1000];

void dfs( ll pos , __int128 k , __int128 now )
{
	if( ans ) return;
	/*
	if( K <= 3 ) {
		int p = now / k + M;
		if( F[pos][p] ) return; else F[pos][p] = 1;
	}*/
	if( now == x && pos != 0 ) {
		for( int i = pos - 1 ; i >= 0 ; --i ) cout << (ll)f[i] << " ";
		cout << "\n"; ans = 1; return;
	}else if( k > N || k < -N ) return;
	__int128 tmp = ( ( ( x - now ) / k )% K + K ) % K;
	for( int i = 0 ; i < v[tmp].size() ; ++i ) {
		f[pos] = v[tmp][i];
		dfs( pos + 1 , k * K , now + k * v[tmp][i] );	
	}
}

int main()
{
	ios :: sync_with_stdio( false );
	cin.tie( 0 );
	ll s1 , s2 , s3 , s4; cin >> s1 >> s2 >> s3 >> s4;
	K = s1; q = s2; D = s3; M = s4; N = 1000000000000000000 * K * 1000;
	for( int i = 1 ; i <= D ; ++i ) {
		cin >> s1; a[i] = s1;
		v[( s1 % K + K ) % K].push_back( s1 );
	}
	while( q -- ) {
		cin >> s1; x = s1; ans = 0;
		dfs( 0 , 1 , 0 );
		for( int i = 0 ; i < 100 ; ++i ) for( int j = 0 ; j < 1000 ; ++j ) F[i][j] = 0; 
		if( !ans ) cout << "IMPOSSIBLE\n";
	}
	return 0;
 } 

詳細信息

Subtask #1:

score: 8
Accepted

Test #1:

score: 8
Accepted
time: 3ms
memory: 29508kb

input:

2 5 2 1
-1 1
773746700847275732
453315765336943587
-762293311961021469
-318959220707754780
-553969845393022639

output:

IMPOSSIBLE
1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 1 -1 -1 1 -1 -1 1 -1 1 -1 1 -1 -1 -1 -1 -1 -1 -1 -1 1 -1 -1 1 -1 -1 1 -1 1 1 -1 1 -1 1 1 1 1 1 1 1 1 1 -1 -1 -1 1 -1 1 -1 1 1 1 1 1 -1 -1 -1 1 
-1 -1 1 -1 1 -1 1 1 -1 1 -1 1 1 1 1 -1 -1 1 -1 1 -1 -1 1 -1 -1 -1 1 -1 1 1 -1 -1 -1 -1 1 -1 1 1 1 1 -1 1 ...

result:

ok all correct! (5 test cases)

Test #2:

score: 8
Accepted
time: 2ms
memory: 29536kb

input:

3 5 3 2
-1 1 -2
-64769061426161351
112463849541202192
962179376182142999
567667672301650531
0

output:

-1 -1 1 -2 1 -2 -2 1 -1 1 1 -2 -1 1 1 -2 -1 -1 1 1 -2 -1 1 1 1 -1 1 1 -2 -2 -1 1 -1 1 -2 1 
1 -1 1 -1 1 -1 1 -2 -1 1 -2 -1 -1 1 1 1 -2 -2 -2 -2 1 -1 1 -1 -1 1 1 -2 1 -2 -2 1 1 1 -2 1 -2 
IMPOSSIBLE
1 1 -1 1 1 -2 -2 1 -2 -2 1 -2 1 -2 1 1 -1 1 1 1 -1 1 1 1 -2 -2 -1 -1 -1 1 -2 -2 1 -2 1 1 1 1 
IMPOSSIBLE

result:

ok all correct! (5 test cases)

Test #3:

score: 8
Accepted
time: 2ms
memory: 30128kb

input:

4 5 4 3
-1 1 -2 2
-687769415104027786
-132741329978291917
3
597501322135844213
784270274532826454

output:

-2 -1 -2 -1 1 1 -2 1 -1 2 -2 -2 -1 1 -2 -1 -2 -2 -2 -2 -2 1 -1 -2 1 -1 2 -1 2 -2 
-2 1 -1 -2 1 -2 -1 -2 1 -2 -1 2 -1 -1 -1 1 -1 2 2 1 -2 -2 1 -2 1 1 -1 1 -1 
1 -1 
IMPOSSIBLE
1 -1 -1 -1 2 1 -2 1 1 -1 -2 -1 -1 -2 1 -1 1 1 -2 -2 -1 -1 2 -2 -2 -1 2 -2 -2 -2 -2 

result:

ok all correct! (5 test cases)

Test #4:

score: 8
Accepted
time: 3ms
memory: 30200kb

input:

5 5 5 4
3 4 0 -1 -4
-399978227049606484
-498082466041246931
785846468494151708
0
-114329597274685627

output:

IMPOSSIBLE
-1 4 4 4 4 4 4 -4 4 -4 0 3 -4 0 4 -4 3 3 3 4 0 3 -4 4 3 -4 -4 -1 4 3 -1 -1 
3 -1 -4 -1 3 0 0 4 4 3 3 -4 -4 4 4 3 4 0 0 0 3 3 -1 -1 -4 3 
0 
-1 4 4 4 4 4 4 3 0 3 -4 -4 0 4 0 4 3 -1 -1 -1 3 0 -4 -4 4 0 0 3 -1 4 4 3 

result:

ok all correct! (5 test cases)

Test #5:

score: 8
Accepted
time: 2ms
memory: 31124kb

input:

10 5 10 9
-6 6 -8 5 3 9 7 0 -7 -5
-361218000084439375
600354983713177383
959338306835291356
647957832334668345
-521605757057494156

output:

IMPOSSIBLE
IMPOSSIBLE
9 5 9 3 3 9 -7 0 6 9 -7 5 3 0 -8 -7 5 6 
7 -6 7 9 5 7 9 -7 3 -6 -6 -6 6 6 9 -6 -6 5 
-6 7 9 -7 9 5 -8 5 -8 9 5 -8 5 0 5 9 -5 -6 

result:

ok all correct! (5 test cases)

Test #6:

score: 8
Accepted
time: 4ms
memory: 30352kb

input:

401 5 401 400
-195 -356 226 -391 -162 -212 243 -157 -110 301 168 -84 -65 -276 364 -302 138 -335 -299 218 313 -9 348 47 -332 -277 151 23 389 181 -230 -117 344 -210 -215 54 187 -106 82 -130 -15 95 -280 -244 -220 281 -324 -152 -36 376 219 164 -231 175 192 11 77 369 -137 -325 78 350 -44 314 57 324 -105 ...

output:

-1 400 400 356 -324 93 218 -206 -106 135 
23 -276 -252 -72 184 190 -257 
IMPOSSIBLE
-81 -204 281 47 87 -324 94 
IMPOSSIBLE

result:

ok all correct! (5 test cases)

Test #7:

score: 8
Accepted
time: 0ms
memory: 29988kb

input:

6 5 6 5
3 1 0 5 2 -2
-1000000000000000000
-19869544093570718
1000000000000000000
-5
5

output:

IMPOSSIBLE
IMPOSSIBLE
1 1 3 3 3 0 2 2 2 2 5 3 5 5 5 3 1 -2 3 2 5 3 5 -2 
IMPOSSIBLE
5 

result:

ok all correct! (5 test cases)

Test #8:

score: 8
Accepted
time: 1ms
memory: 30892kb

input:

7 5 7 6
-4 0 -5 -3 -6 -2 -1
332477985489826561
-499984603195203871
-81876578279226946
-65312525802835891
102944041712615081

output:

IMPOSSIBLE
-6 -1 -6 0 -1 -5 -6 -6 0 -3 -4 -4 0 -3 -2 -4 -3 -3 -2 -5 -3 
-1 0 -1 -1 -6 -5 0 -1 -2 -3 -6 -6 -6 -4 -2 -5 -3 -6 -4 -3 -5 
-5 -5 0 -5 -2 0 -3 -2 -1 -6 -2 -1 -2 -5 -3 -3 -3 -3 -4 -6 
IMPOSSIBLE

result:

ok all correct! (5 test cases)

Subtask #2:

score: 0
Time Limit Exceeded

Dependency #1:

100%
Accepted

Test #9:

score: 17
Accepted
time: 3ms
memory: 30360kb

input:

2 5 4 400
156 97 -245 376
5
-561310785184682687
794452803606918271
-774192623069805183
0

output:

97 -245 97 -245 376 156 97 156 97 97 97 97 97 156 97 97 97 156 97 156 97 156 156 97 156 156 97 97 97 156 156 156 156 97 97 156 97 156 156 156 156 156 97 156 156 156 97 156 97 156 97 97 156 97 97 156 156 156 97 97 97 97 156 156 97 156 97 97 156 97 
156 -245 -245 97 97 156 156 156 156 97 97 156 97 97 ...

result:

ok all correct! (5 test cases)

Test #10:

score: 17
Accepted
time: 3ms
memory: 29336kb

input:

3 5 6 400
-391 -147 68 -369 269 29
-648964802307752880
940185303376914152
632799205919718748
794958765304745262
-11

output:

68 -147 -147 -147 269 -147 68 29 -147 -369 -147 -147 -147 -391 -147 -147 269 -147 -147 -369 269 -147 -369 -147 -391 -391 -147 -147 -391 -147 -369 -147 -369 -369 -369 -369 -369 -369 -369 -369 -369 -369 -369 269 -391 -147 
29 68 -369 -369 269 29 -147 -369 -369 -147 -147 -391 -147 -369 -369 -147 -147 2...

result:

ok all correct! (5 test cases)

Test #11:

score: 17
Accepted
time: 2ms
memory: 29456kb

input:

4 5 7 400
253 -98 100 15 245 -181 -304
0
-176117779103059637
433058074753795030
318213338928754731
3

output:

15 15 -304 100 -304 -98 -181 253 -98 253 -98 253 253 -98 100 100 -98 100 -98 -98 100 253 100 -98 15 -98 253 100 15 100 -98 -98 -98 15 100 
15 15 -304 100 -304 -98 -181 245 15 -181 -181 -98 15 -98 100 15 -98 253 15 100 253 253 100 -98 253 100 253 100 -98 -98 15 15 100 15 15 
15 -98 100 253 -98 -304 -...

result:

ok all correct! (5 test cases)

Test #12:

score: 17
Accepted
time: 4ms
memory: 29352kb

input:

5 5 12 400
209 41 178 -298 45 -2 -230 -366 86 -169 186 295
-378437136233643628
0
2
-174597539538654279
140849898785777575

output:

86 -366 -366 178 209 209 178 209 178 209 41 209 45 178 178 209 -298 209 209 41 -298 -298 45 41 209 209 45 209 41 45 209 -298 
45 -169 -298 45 209 45 178 41 -298 45 209 45 178 41 -298 45 209 45 178 41 -298 45 209 41 178 41 209 45 41 45 
-2 45 -230 209 295 178 41 -298 45 209 45 178 41 -298 45 209 45 1...

result:

ok all correct! (5 test cases)

Test #13:

score: 17
Accepted
time: 1ms
memory: 30612kb

input:

2 5 30 400
237 -278 95 356 -165 -142 28 144 348 -389 299 -378 143 200 -232 84 -175 -17 -148 1 -118 -3 400 20 -319 -350 -242 37 136 -7
493237789890998250
-614929943217873018
218053785628599093
822752920824523903
-634674198752739282

output:

-118 -7 356 237 237 -278 -278 237 -278 237 -278 237 237 -278 -278 237 237 237 237 237 237 237 237 237 237 237 -278 237 237 -278 -278 -278 237 -278 -278 237 -278 -278 -278 -278 -278 237 -278 -278 237 237 237 237 237 -278 237 -278 -278 -278 -278 -278 237 237 -278 -278 237 237 237 237 -278 -278 237 237...

result:

ok all correct! (5 test cases)

Test #14:

score: 17
Accepted
time: 4ms
memory: 30312kb

input:

3 5 30 400
-86 -153 347 211 274 24 -275 256 55 -40 49 -350 43 345 -373 -216 -17 378 210 -213 -303 -332 -387 -113 -285 -362 -122 279 -152 -396
-981987992952554485
-947573277489565640
-601032896574520671
-385638561389044355
-752413262440882787

output:

-122 345 -40 347 -86 -86 -86 347 -153 -153 -86 -153 347 -153 347 -153 -86 -86 -86 -153 347 347 -86 -86 -86 -153 -86 -153 -153 -153 347 -86 -86 347 -153 -86 -86 -86 347 347 -86 -153 -153 -86 -86 347 
55 -153 -153 347 -153 347 347 347 -153 -86 -86 347 347 -153 347 -86 -153 -153 -86 -153 -153 -86 -153 ...

result:

ok all correct! (5 test cases)

Test #15:

score: 17
Accepted
time: 2ms
memory: 29260kb

input:

4 5 30 400
274 -183 -80 -376 90 295 -392 -310 -203 -391 226 59 -126 -85 108 -219 -88 26 -6 2 167 -185 -131 -315 -171 165 276 -211 -207 317
-248426308921810546
782928747458189810
0
686628409348712959
-930425985281589892

output:

26 -85 -80 -80 295 295 295 -183 -183 274 274 -80 274 -183 -183 -183 -80 -80 274 274 295 -183 -183 295 -80 274 -80 274 -183 295 274 -183 295 274 295 274 
59 -183 -183 -183 274 -80 274 -80 274 -183 -183 -183 274 274 274 274 295 274 274 -183 274 274 -183 -183 295 -183 -80 295 -183 -183 -80 274 -80 274 ...

result:

ok all correct! (5 test cases)

Test #16:

score: 17
Accepted
time: 3ms
memory: 30304kb

input:

9 5 5 400
337 -240 341 383 80
550583341400510570
173595647051659241
72187827096576649
-230165571686662744
226308150325737355

output:

IMPOSSIBLE
80 80 341 383 341 337 337 383 337 -240 -240 -240 337 -240 -240 -240 341 
341 80 80 -240 383 337 80 341 337 337 337 383 341 383 80 337 
IMPOSSIBLE
80 337 337 341 337 341 -240 -240 383 383 383 -240 383 383 337 337 337 

result:

ok all correct! (5 test cases)

Test #17:

score: 17
Accepted
time: 2ms
memory: 29160kb

input:

1000000 5 801 400
23 -353 3 -392 -54 -156 381 252 -400 -13 379 211 222 316 275 -218 376 51 210 -175 -125 40 397 253 369 127 -222 112 -44 -241 -328 -145 -205 -111 -348 -36 -330 378 47 179 95 -157 48 -61 90 -256 -71 124 -263 150 182 -396 -245 45 202 -373 -181 139 -12 244 -301 197 145 231 80 -234 -272 ...

output:

IMPOSSIBLE
72 271 -295 
78 261 -139 
IMPOSSIBLE
-133 361 90 

result:

ok all correct! (5 test cases)

Test #18:

score: 17
Accepted
time: 2ms
memory: 29196kb

input:

2 5 400 400
-27 274 391 204 -133 -384 -276 250 7 276 -209 178 162 -251 -85 221 -337 -176 98 -104 119 -327 271 -137 186 -113 -202 278 -400 273 122 260 -181 -370 -7 -208 -280 -158 23 166 360 215 -323 -76 -247 232 73 247 211 -207 -231 220 -116 -318 -390 65 261 -73 177 317 107 -56 333 123 -53 307 -221 3...

output:

-113 -27 274 274 274 -27 274 274 274 -27 -27 -27 274 -27 -27 274 -27 -27 -27 -27 -27 274 -27 274 -27 -27 274 -27 274 274 274 -27 274 274 274 -27 274 -27 274 274 274 -27 274 274 274 274 -27 -27 274 274 274 274 -27 274 274 274 -27 274 274 274 274 -27 -27 274 274 -27 -27 274 274 274 -27 
-17 -27 -27 27...

result:

ok all correct! (5 test cases)

Test #19:

score: 17
Accepted
time: 1ms
memory: 30112kb

input:

2 5 798 400
-124 -330 57 -141 -266 -376 23 146 396 205 163 354 -338 181 297 -207 -83 216 265 -183 -272 101 -41 -176 -204 -107 -135 246 208 -329 -315 7 282 -3 -264 395 305 -85 184 -270 138 332 -370 -155 307 -86 375 -60 -398 250 322 159 -198 321 -256 -250 372 -365 286 206 -355 -72 -362 369 -187 -108 1...

output:

86 -124 -124 57 57 -124 57 -124 57 57 -124 57 57 57 57 57 -124 57 57 57 57 57 57 -124 -124 -124 57 -124 57 57 -124 57 57 57 57 -124 -124 -124 57 -124 57 57 57 -124 -124 -124 57 -124 -124 -124 57 -124 57 57 57 57 -124 -124 -124 -124 57 -124 -124 -124 57 57 57 -124 57 57 57 
26 57 -124 -124 -124 57 -1...

result:

ok all correct! (5 test cases)

Test #20:

score: 17
Accepted
time: 1ms
memory: 30488kb

input:

10 5 4 400
-4 -2 -6 -8
-424248844866644462
-707481080364274331
-84484666642484224
595262179988413424
-282662246642882646

output:

-4 -2 -4 -2 -4 -8 -8 -4 -4 -8 -6 -6 -6 -4 -4 -4 -6 -2 
IMPOSSIBLE
-8 -4 -4 -8 -4 -6 -6 -6 -6 -4 -2 -4 -8 -4 -2 -2 -4 
IMPOSSIBLE
-2 -8 -2 -6 -6 -2 -2 -4 -6 -6 -4 -2 -8 -8 -2 -6 -4 -6 

result:

ok all correct! (5 test cases)

Test #21:

score: 0
Time Limit Exceeded

input:

2 5 50 400
-238 -80 -44 -305 -7 -173 -282 -241 -96 -67 -395 -283 -362 -83 -398 -204 -171 -365 -77 -94 -163 -325 -346 -155 -347 -237 -200 -161 -353 -126 -331 -215 -285 -182 -189 -187 -55 -247 -268 -11 -399 -255 -52 -332 -168 -274 -185 -60 -29 -257
1000000000000000000
0
-1000000000000000000
-1
-403279...

output:


result: