QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#464278 | #5523. Graph Problem With Small $n$ | BalintR | TL | 0ms | 3788kb | C++20 | 2.2kb | 2024-07-06 00:02:42 | 2024-07-06 00:02:42 |
Judging History
answer
#include <bits/stdc++.h>
#include <immintrin.h>
using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef complex<double> cpx;
template <typename T> using minPq = priority_queue<T, vector<T>, greater<T>>;
#define ms(a, x) memset(a, x, sizeof(a))
#define pb push_back
#define fs first
#define sn second
#define ALL(v) begin(v), end(v)
#define SZ(v) ((int) (v).size())
#define lbv(v, x) (lower_bound(ALL(v), x) - (v).begin())
#define ubv(v, x) (upper_bound(ALL(v), x) - (v).begin())
template <typename T> inline void UNIQUE(vector<T> &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
#define FR(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define dbg(x) {cerr << #x << ' ' << x << endl;}
#define dbgArr(arr, n) {cerr << #arr; FR(_i, n) cerr << ' ' << (arr)[_i]; cerr << endl;}
template <typename T, typename U>
ostream& operator<<(ostream &os, pair<T, U> p){return os << "(" << p.fs << ", " << p.sn << ")";}
const int MN = 24;
int n;
int adjMat[MN], iAdjMat[MN], ans[MN];
int dp[1<<(MN-1)];
#define proc(n1) dp[s1 | (1 << n1)] |= adjMat[n1] & -((inc >> n1) & 1);
void run(){
dp[0] = adjMat[n-1];
FR(s1, 1<<(n-1)){
int inc = dp[s1] &= ~s1;
FR(n1, n-1) proc(n1);
}
}
void solve(){
FR(src, n){
vi ord(n);
iota(ALL(ord), 0);
swap(ord[src], ord[n-1]);
ms(adjMat, 0);
FR(i, n) FR(j, n) adjMat[i] |= ((iAdjMat[ord[i]] >> ord[j]) & 1) << j;
fill_n(dp, 1<<(n-1), 0);
run();
int mask = (1<<(n-1)) - 1;
FR(n1, n) if(n1 != src) ans[src] |= ((dp[mask ^ (1 << ord[n1])] >> ord[n1]) & 1) << n1;
}
}
int main(){
cin.sync_with_stdio(0); cin.tie(0);
cin >> n;
FR(i, n){
string str; cin >> str;
FR(j, n) iAdjMat[i] |= (str[j]-'0') << j;
}
solve();
FR(i, n){
FR(j, n) cout << ((ans[i] >> j) & 1);
cout << '\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
input:
4 0110 1010 1101 0010
output:
0001 0001 0000 1100
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3652kb
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: 3788kb
input:
4 0111 1011 1101 1110
output:
0111 1011 1101 1110
result:
ok 4 lines
Test #4:
score: -100
Time Limit Exceeded
input:
23 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 00000000000000000000000 000000000...