QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#403451 | #7740. Puzzle: Question Mark | Godwang | AC ✓ | 225ms | 19356kb | C++14 | 6.4kb | 2024-05-02 13:24:13 | 2024-05-02 13:24:13 |
Judging History
answer
#include <iostream>
using namespace std;
#include <set>
#include <algorithm>
#include <cmath>
#include <map>
#include <cstdio>
#include <string>
#include <cstring>
#include <string.h>
#include <stdlib.h>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <stack>
#include <queue>
#include <ctype.h>
#include <vector>
#include <random>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, a, n) for (int i = n; i >= a; i--)
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define endl '\n'
const double pai = acos(-1);
ll extend_gcd(ll a, ll b, ll &x, ll &y)
{
if (b == 0)
{
x = 1;
y = 0;
return a;
}
ll d = extend_gcd(b, a % b, y, x);
y -= a / b * x;
return d;
}
ll fastpow(ll a, ll n, ll mod)
{
ll ans = 1;
a %= mod;
while (n)
{
if (n & 1)
ans = (ans * a)%mod; //% mod
a = (a * a)%mod; //% mod
n >>= 1;
}
return ans;
}
int dir[4][2] =
{
{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; // d a w s
const double inf = 1000000000000000000;
const ll mod = 1e9 + 7, P1 = 13331;
const double eps = 1e-7;
const int N = 2e3 + 10, M = 1e6 + 10;
int t,n;
int a[N][N];
int cnt;
void solve24(int hang,int lie)
{
a[hang][lie]=a[hang+1][lie]=a[hang][lie+1]=a[hang+1][lie+2]=++cnt;
a[hang+1][lie+1]=a[hang][lie+2]=a[hang][lie+3]=a[hang+1][lie+3]=++cnt;
}
void solve42(int hang,int lie)
{
a[hang][lie]=a[hang][lie+1]=a[hang+1][lie+1]=a[hang+2][lie]=++cnt;
a[hang+1][lie]=a[hang+2][lie+1]=a[hang+3][lie]=a[hang+3][lie+1]=++cnt;
}
void solve3311(int hang,int lie)
{
a[hang+1][lie]=a[hang+1][lie+1]=a[hang+2][lie]=a[hang+2][lie+2]=++cnt;
a[hang][lie+1]=a[hang][lie+2]=a[hang+1][lie+2]=a[hang+2][lie+1]=++cnt;
}
void solve3313(int hang,int lie)
{
a[hang][lie]=a[hang][lie+1]=a[hang+1][lie]=a[hang+2][lie+1]=++cnt;
a[hang+1][lie+1]=a[hang+1][lie+2]=a[hang+2][lie]=a[hang+2][lie+2]=++cnt;
}
void solve3331(int hang,int lie)
{
a[hang][lie]=a[hang][lie+1]=a[hang+1][lie]=a[hang+1][lie+2]=++cnt;
a[hang][lie+2]=a[hang+1][lie+1]=a[hang+2][lie+1]=a[hang+2][lie+2]=++cnt;
}
void solve3333(int hang,int lie)
{
a[hang][lie]=a[hang+1][lie+1]=a[hang+2][lie]=a[hang+2][lie+1]=++cnt;
a[hang+1][lie]=a[hang][lie+1]=a[hang][lie+2]=a[hang+1][lie+2]=++cnt;
}
void solve5(int hang,int lie)
{
solve24(hang,lie);
solve3313(hang+2,lie);
a[hang+2][lie+3]=a[hang+3][lie+4]=a[hang+4][lie+3]=a[hang+4][lie+4]=++cnt;
}
void solve7(int hang,int lie)
{
solve3333(hang,lie);
solve24(hang+3,lie);
solve24(hang+5,lie);
solve42(hang,lie+5);
solve3311(hang+4,lie+4);
a[hang][lie+3]=a[hang+1][lie+4]=a[hang+2][lie+3]=a[hang+2][lie+4]=++cnt;
}
void te(int hang,int lie)
{
a[hang][lie]=a[hang][lie+1]=a[hang+1][lie]=a[hang+1][lie+2]=++cnt;
a[hang+1][lie+1]=a[hang+1][lie+3]=a[hang+2][lie+2]=a[hang+2][lie+3]=++cnt;
}
void solve9(int hang,int lie)
{
te(hang+2,lie+3);
te(hang+4,lie+2);
solve24(hang,lie);
solve24(hang+7,lie+5);
solve42(hang,lie+7);
solve42(hang+5,lie);
solve3331(hang,lie+4);
solve3333(hang+2,lie);
solve3313(hang+6,lie+2);
solve3311(hang+4,lie+6);
}
void solve(int hang,int lie)
{
if(n<=9)
{
//
// return;
//
solve9(hang,lie);
return;
}
for(int j=1;j+3<=n/4*4-4;j+=4)
{
solve24(hang,j);
solve24(hang+n-2,j);
}
//huang
// cout<<cnt<<endl;
a[hang][n-4]=a[hang][n-3]=a[hang+1][n-4]=a[hang+2][n-3]=++cnt;
a[hang+1][n-3]=a[hang+2][n-2]=a[hang+3][n-3]=a[hang+3][n-2]=++cnt;
a[hang+n-6][n-1]=a[hang+n-6][n]=a[hang+n-5][n-2]=a[hang+n-5][n]=++cnt;
a[hang+n-5][n-3]=a[hang+n-5][n-1]=a[hang+n-4][n-3]=a[hang+n-4][n-2]=++cnt;
//lv
solve3311(hang+n-3,n-4);
solve3331(hang,n-2);
//youxia
solve42(hang+n-4,n-1);
for(int i=hang+3; i+3<=hang+n-7 ;i+=4)
{
solve42(i,n-1);
solve42(i+1,n-3);
}
//
//
n-=4;
solve(hang+2,1);
}
int main()
{
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// freopen("ain.txt", "r", stdin);freopen("aout.txt", "w", stdout);
cin>>t;
while(t--)
{
cnt=0;
cin>>n;
int tem=n;
rep(i,1,n)
{
rep(j,1,n)
{
a[i][j]=0;
}
}
if(n%4==0)
{
for(int i=1;i<=n;i+=2)
{
for(int j=1;j<=n;j+=4)
{
solve24(i,j);
}
}
}
else if(n%2==0)
{
for(int i=1;i<=n;i+=2)
{
for(int j=1;j+3<=n;j+=4)
{
solve24(i,j);
}
}
for(int i=1;i+3<=n;i+=4)
{
solve42(i,n-1);
}
}
else
{
if(n==1)
{
}
else if(n==3)
{
solve3333(1,1);
}
else if(n==5)
{
solve5(1,1);
}
else if(n==7)
{
solve7(1,1);
}
else if(n==9)
{
solve9(1,1);
}
else
{
if(n%4==3)
{
int k=n/4;
solve3311(1+4*k,1+4*k);
for(int j=1;j<=4*k;j+=4)
{
solve24(4*k+2,j);
}
for(int i=1;i<=4*k;i+=4)
{
solve42(i,4*k+2);
}
n-=2;
}
solve(1,1);
}
}
cout<<cnt<<endl;
rep(i,1,tem)
{
rep(j,1,tem)
{
if(j>1)
{
cout<<" ";
}
cout<<a[i][j];
}
cout<<endl;
}
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3620kb
input:
2 3 4
output:
2 1 2 2 2 1 2 1 1 0 4 1 1 2 2 1 2 1 2 3 3 4 4 3 4 3 4
result:
ok Correct. (2 test cases)
Test #2:
score: 0
Accepted
time: 204ms
memory: 4796kb
input:
246 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 ...
output:
0 0 0 0 0 0 0 2 1 2 2 2 1 2 1 1 0 4 1 1 2 2 1 2 1 2 3 3 4 4 3 4 3 4 5 1 1 2 2 0 1 2 1 2 0 3 3 0 5 0 3 4 4 0 5 4 3 4 5 5 8 1 1 2 2 7 7 1 2 1 2 8 7 3 3 4 4 7 8 3 4 3 4 8 8 5 5 6 6 0 0 5 6 5 6 0 0 11 1 2 2 11 0 7 7 2 1 2 0 11 8 7 1 1 0 11 11 7 8 3 3 4 4 0 8 8 3 4 3 4 0 10 10 5 5 6 6 9 9 10 5 6 5 6 9 10...
result:
ok Correct. (246 test cases)
Test #3:
score: 0
Accepted
time: 210ms
memory: 5248kb
input:
64 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
output:
15252 247 247 248 248 251 251 252 252 255 255 256 256 259 259 260 260 263 263 264 264 267 267 268 268 271 271 272 272 275 275 276 276 279 279 280 280 283 283 284 284 287 287 288 288 291 291 292 292 295 295 296 296 299 299 300 300 303 303 304 304 307 307 308 308 311 311 312 312 315 315 316 316 319 31...
result:
ok Correct. (64 test cases)
Test #4:
score: 0
Accepted
time: 190ms
memory: 5516kb
input:
45 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
output:
24180 311 311 312 312 315 315 316 316 319 319 320 320 323 323 324 324 327 327 328 328 331 331 332 332 335 335 336 336 339 339 340 340 343 343 344 344 347 347 348 348 351 351 352 352 355 355 356 356 359 359 360 360 363 363 364 364 367 367 368 368 371 371 372 372 375 375 376 376 379 379 380 380 383 38...
result:
ok Correct. (45 test cases)
Test #5:
score: 0
Accepted
time: 207ms
memory: 5724kb
input:
35 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
output:
31684 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52 52 ...
result:
ok Correct. (35 test cases)
Test #6:
score: 0
Accepted
time: 192ms
memory: 5960kb
input:
30 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
output:
38220 391 391 392 392 395 395 396 396 399 399 400 400 403 403 404 404 407 407 408 408 411 411 412 412 415 415 416 416 419 419 420 420 423 423 424 424 427 427 428 428 431 431 432 432 435 435 436 436 439 439 440 440 443 443 444 444 447 447 448 448 451 451 452 452 455 455 456 456 459 459 460 460 463 46...
result:
ok Correct. (30 test cases)
Test #7:
score: 0
Accepted
time: 212ms
memory: 19236kb
input:
2 2000 1000
output:
1000000 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52 5...
result:
ok Correct. (2 test cases)
Test #8:
score: 0
Accepted
time: 209ms
memory: 19356kb
input:
2 1999 999
output:
999000 1999 1999 2000 2000 2003 2003 2004 2004 2007 2007 2008 2008 2011 2011 2012 2012 2015 2015 2016 2016 2019 2019 2020 2020 2023 2023 2024 2024 2027 2027 2028 2028 2031 2031 2032 2032 2035 2035 2036 2036 2039 2039 2040 2040 2043 2043 2044 2044 2047 2047 2048 2048 2051 2051 2052 2052 2055 2055 205...
result:
ok Correct. (2 test cases)
Test #9:
score: 0
Accepted
time: 211ms
memory: 19352kb
input:
2 1998 998
output:
998000 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52 52...
result:
ok Correct. (2 test cases)
Test #10:
score: 0
Accepted
time: 195ms
memory: 19232kb
input:
2 1997 997
output:
997002 1 1 2 2 5 5 6 6 9 9 10 10 13 13 14 14 17 17 18 18 21 21 22 22 25 25 26 26 29 29 30 30 33 33 34 34 37 37 38 38 41 41 42 42 45 45 46 46 49 49 50 50 53 53 54 54 57 57 58 58 61 61 62 62 65 65 66 66 69 69 70 70 73 73 74 74 77 77 78 78 81 81 82 82 85 85 86 86 89 89 90 90 93 93 94 94 97 97 98 98 101...
result:
ok Correct. (2 test cases)
Test #11:
score: 0
Accepted
time: 225ms
memory: 19280kb
input:
2 1996 996
output:
996004 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52 52...
result:
ok Correct. (2 test cases)
Test #12:
score: 0
Accepted
time: 223ms
memory: 19240kb
input:
2 1995 995
output:
995006 1995 1995 1996 1996 1999 1999 2000 2000 2003 2003 2004 2004 2007 2007 2008 2008 2011 2011 2012 2012 2015 2015 2016 2016 2019 2019 2020 2020 2023 2023 2024 2024 2027 2027 2028 2028 2031 2031 2032 2032 2035 2035 2036 2036 2039 2039 2040 2040 2043 2043 2044 2044 2047 2047 2048 2048 2051 2051 205...
result:
ok Correct. (2 test cases)
Test #13:
score: 0
Accepted
time: 197ms
memory: 19196kb
input:
2 1994 994
output:
994008 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52 52...
result:
ok Correct. (2 test cases)
Test #14:
score: 0
Accepted
time: 221ms
memory: 19312kb
input:
2 1993 993
output:
993012 1 1 2 2 5 5 6 6 9 9 10 10 13 13 14 14 17 17 18 18 21 21 22 22 25 25 26 26 29 29 30 30 33 33 34 34 37 37 38 38 41 41 42 42 45 45 46 46 49 49 50 50 53 53 54 54 57 57 58 58 61 61 62 62 65 65 66 66 69 69 70 70 73 73 74 74 77 77 78 78 81 81 82 82 85 85 86 86 89 89 90 90 93 93 94 94 97 97 98 98 101...
result:
ok Correct. (2 test cases)
Test #15:
score: 0
Accepted
time: 218ms
memory: 19156kb
input:
2 1992 992
output:
992016 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52 52...
result:
ok Correct. (2 test cases)
Test #16:
score: 0
Accepted
time: 213ms
memory: 19232kb
input:
2 1991 991
output:
991020 1991 1991 1992 1992 1995 1995 1996 1996 1999 1999 2000 2000 2003 2003 2004 2004 2007 2007 2008 2008 2011 2011 2012 2012 2015 2015 2016 2016 2019 2019 2020 2020 2023 2023 2024 2024 2027 2027 2028 2028 2031 2031 2032 2032 2035 2035 2036 2036 2039 2039 2040 2040 2043 2043 2044 2044 2047 2047 204...
result:
ok Correct. (2 test cases)
Extra Test:
score: 0
Extra Test Passed