QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#465492 | #5523. Graph Problem With Small $n$ | BalintR | WA | 55ms | 29628kb | C++20 | 2.0kb | 2024-07-06 23:05:36 | 2024-07-06 23:05:37 |
Judging History
answer
#include <stdio.h>
#pragma GCC target "avx2"
#include <immintrin.h>
typedef __m256i m256;
#define vand(a, b) _mm256_and_si256(a, b)
#define vor(a, b) _mm256_or_si256(a, b)
#define FR(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
const int MN = 24;
int n;
int adjMat[1<<MN];
int dp[1<<(MN-1)];
__attribute__((optimize("Os"))) void calcDp(){
dp[0] = 1<<(n-1);
FOR(s2, 1, 1<<(n-1)){
int v = 0, s = s2;
while(s){
int x = s & -s;
int s1 = s2 ^ (s & -s);
s ^= s & -s;
if(!(dp[s1] & adjMat[x])) x = 0;
v |= x;
}
dp[s2] = v;
}
}
int main(){
scanf("%d\n", &n);
FR(i, n){
FR(j, n) adjMat[1<<i] |= (getchar()-'0') << j;
getchar();
}
calcDp();
int mask = (1<<(n-1))-1;
m256 zeroV = _mm256_setzero_si256();
m256 ans1 = zeroV, ans2 = zeroV, ans3 = zeroV;
m256 bits1 = _mm256_setr_epi32(1<<0, 1<<1, 1<<2, 1<<3, 1<<4, 1<<5, 1<<6, 1<<7);
m256 bits2 = _mm256_setr_epi32(1<<8, 1<<9, 1<<10, 1<<11, 1<<12, 1<<13, 1<<14, 1<<15);
m256 bits3 = _mm256_setr_epi32(1<<16, 1<<17, 1<<18, 1<<19, 1<<20, 1<<21, 1<<22, 1<<23);
FR(s1, 1<<(n-2)){
m256 xVec = _mm256_set1_epi32(dp[s1]);
m256 yVec = _mm256_set1_epi32(dp[s1^mask]);
m256 v1 = vand(yVec, _mm256_cmpeq_epi32(bits1, vand(xVec, bits1)));
m256 v2 = vand(yVec, _mm256_cmpeq_epi32(bits2, vand(xVec, bits2)));
m256 v3 = vand(yVec, _mm256_cmpeq_epi32(bits3, vand(xVec, bits3)));
ans1 = vor(ans1, v1);
ans2 = vor(ans1, v2);
ans3 = vor(ans1, v3);
}
int ansArr[24];
_mm256_storeu_si256((m256*) (ansArr), ans1);
_mm256_storeu_si256((m256*) (ansArr+8), ans2);
_mm256_storeu_si256((m256*) (ansArr+16), ans3);
FR(i, n){
FR(j, n) putchar('0' + ((ansArr[i] & (1<<j)) || (ansArr[j] & (1<<i))));
putchar('\n');
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3404kb
input:
4 0110 1010 1101 0010
output:
0001 0001 0000 1100
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3492kb
input:
6 010001 101000 010100 001010 000101 100010
output:
010001 101000 010100 001010 000101 100010
result:
ok 6 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 3408kb
input:
4 0111 1011 1101 1110
output:
0111 1011 1101 1110
result:
ok 4 lines
Test #4:
score: 0
Accepted
time: 50ms
memory: 28272kb
input:
23 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 000000000...
output:
00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 000000000000...
result:
ok 23 lines
Test #5:
score: 0
Accepted
time: 49ms
memory: 28064kb
input:
23 00010100000000000101000 00000000010000000001000 00000000000001000000001 10000000000000000010000 00000000000000000000000 10000000000000000000000 00000001000000000000000 00000010000000000010000 00000000000001000000000 01000000000000000000000 00000000000000000000000 00000000000000000000000 000000000...
output:
00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 000000000000...
result:
ok 23 lines
Test #6:
score: 0
Accepted
time: 53ms
memory: 29628kb
input:
23 00001000000000000000000 00001000010001000000000 00000000000101000010000 00001000000100000000000 11010000010011000100000 00000000000100000000000 00000000000000000000001 00000000000000000101000 00000000000000000000000 01001000000000101010010 00000000000000000000101 00110100000010001000000 000010000...
output:
00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 000000000000...
result:
ok 23 lines
Test #7:
score: 0
Accepted
time: 55ms
memory: 28524kb
input:
23 01000000000001101001100 10000001101000000000000 00000100000100010000100 00000000000000001011000 00000100001000000000000 00101000000000001000001 00000000000000000000000 01000000000000000000000 01000000000100000010000 00000000000001000000011 01001000000000010000000 00100000100001000100001 000000000...
output:
00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 000000000000...
result:
ok 23 lines
Test #8:
score: -100
Wrong Answer
time: 54ms
memory: 28496kb
input:
23 00000000010001001001010 00100010001101110000001 01000001000100110000000 00000011010001101100100 00000000010000010001000 00000000000000001001000 01010001000000000000001 00110010000000000000010 00000000011000100100000 10011000101000100000000 01000000110010101010000 01100000000000000000000 000000000...
output:
01111111111111110111111 10011111110111111010111 10011111110111111111111 11101111111111110110111 11110111111111111111111 11111011111111111111111 11111101111111111111110 11111110111111101110111 11111111111111111111111 11111111111111111110111 10011111110111110110110 11111111111111111111111 111111111111...
result:
wrong answer 1st lines differ - expected: '01111111110111110110111', found: '01111111111111110111111'