QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#370855 | #4890. 这是一道集训队胡策题 | chenxinyang2006 | 100 ✓ | 822ms | 126688kb | C++14 | 4.6kb | 2024-03-29 17:46:21 | 2024-03-29 17:46:21 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;
template <class T>
void chkmax(T &x,T y){
if(x < y) x = y;
}
template <class T>
void chkmin(T &x,T y){
if(x > y) x = y;
}
inline int popcnt(int x){
return __builtin_popcount(x);
}
inline int ctz(int x){
return __builtin_ctz(x);
}
template <int P>
class mod_int
{
using Z = mod_int;
private:
static int mo(int x) { return x < 0 ? x + P : x; }
public:
int x;
int val() const { return x; }
mod_int() : x(0) {}
template <class T>
mod_int(const T &x_) : x(x_ >= 0 && x_ < P ? static_cast<int>(x_) : mo(static_cast<int>(x_ % P))) {}
bool operator==(const Z &rhs) const { return x == rhs.x; }
bool operator!=(const Z &rhs) const { return x != rhs.x; }
Z operator-() const { return Z(x ? P - x : 0); }
Z pow(long long k) const
{
Z res = 1, t = *this;
while (k)
{
if (k & 1)
res *= t;
if (k >>= 1)
t *= t;
}
return res;
}
Z &operator++()
{
x < P - 1 ? ++x : x = 0;
return *this;
}
Z &operator--()
{
x ? --x : x = P - 1;
return *this;
}
Z operator++(int)
{
Z ret = x;
x < P - 1 ? ++x : x = 0;
return ret;
}
Z operator--(int)
{
Z ret = x;
x ? --x : x = P - 1;
return ret;
}
Z inv() const { return pow(P - 2); }
Z &operator+=(const Z &rhs)
{
(x += rhs.x) >= P && (x -= P);
return *this;
}
Z &operator-=(const Z &rhs)
{
(x -= rhs.x) < 0 && (x += P);
return *this;
}
Z operator-()
{
return -x;
}
Z &operator*=(const Z &rhs)
{
x = 1ULL * x * rhs.x % P;
return *this;
}
Z &operator/=(const Z &rhs) { return *this *= rhs.inv(); }
#define setO(T, o) \
friend T operator o(const Z &lhs, const Z &rhs) \
{ \
Z res = lhs; \
return res o## = rhs; \
}
setO(Z, +) setO(Z, -) setO(Z, *) setO(Z, /)
#undef setO
friend istream& operator>>(istream& is, mod_int& x)
{
long long tmp;
is >> tmp;
x = tmp;
return is;
}
friend ostream& operator<<(ostream& os, const mod_int& x)
{
os << x.val();
return os;
}
};
using Z = mod_int<mod>;
Z power(Z p,ll k){
Z ans = 1;
while(k){
if(k % 2 == 1) ans *= p;
p *= p;
k /= 2;
}
return ans;
}
int n;
char str[5005][5005];
int G[5005][5005];
int N,vis[10005],ord[10005];
void dfs(int u){
vis[u] = 1;
if(u <= n){
rep(v,1,n) if(G[u][v] && !vis[v + n]) dfs(v + n);
}else{
rep(v,1,n) if(!G[v][u - n] && !vis[v]) dfs(v);
}
ord[++N] = u;
}
int cL,cR;
void dfs2(int u,int c){
if(u <= n) cL++;
else cR++;
vis[u] = c;
if(u <= n){
rep(v,1,n) if(!G[u][v] && !vis[v + n]) dfs2(v + n,c);
}else{
rep(v,1,n) if(G[v][u - n] && !vis[v]) dfs2(v,c);
}
}
int k;
int a[10005];
Z P[10005];
int main(){
// freopen("test.in","r",stdin);
scanf("%d",&n);
P[0] = 1;
rep(i,1,n) P[i] = P[i - 1] + P[i - 1];
rep(i,1,n){
scanf("%s",str[i] + 1);
rep(j,1,n) G[i][j] = str[i][j] - '0';
}
rep(u,1,2 * n) if(!vis[u]) dfs(u);
memset(vis,0,sizeof(vis));
per(i,2 * n,1){
if(!vis[ord[i]]){
cL = cR = 0;
dfs2(ord[i],ord[i]);
if(!cR) a[++k] = 0;
else if(!cL) a[++k] = 1;
else a[++k] = 2;
}
}
// rep(i,1,k) printf("%d ",a[i]);
// printf("\n");
Z ans = 1;
for(int l = 1,r;l <= k;l = r + 1){
r = l;
if(a[l] == 2){
ans++;
continue;
}
while(r < k && a[r + 1] == a[r]) r++;
ans += P[r - l + 1] - 1;
}
printf("%d\n",ans.val());
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 1ms
memory: 3980kb
input:
10 0000000000 0101111001 0101111001 0101111001 0101111001 0101111001 0101111001 0101111001 0101111001 0101111001
output:
591
result:
ok 1 number(s): "591"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3984kb
input:
10 0000000000 0001100000 0001111111 0001111111 0001100000 0001111111 0001110100 0001110100 0001110100 0001110100
output:
47
result:
ok 1 number(s): "47"
Test #3:
score: 0
Accepted
time: 1ms
memory: 4068kb
input:
10 1000000000 1010000000 1010000000 1010111111 1010100111 1010100111 1010100111 1010100100 1010100100 1010100110
output:
30
result:
ok 1 number(s): "30"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3908kb
input:
10 0000110001 0101100000 0100001111 1011000001 0011010000 1010011111 1000111100 1110111101 1000101100 1000110100
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3964kb
input:
10 1000010100 1100001111 1111010111 1010000001 1000110111 0100001001 1000111110 0110100010 1010100010 1010110111
output:
2
result:
ok 1 number(s): "2"
Test #6:
score: 0
Accepted
time: 0ms
memory: 4072kb
input:
10 1011001000 1011111011 0111010011 0011110000 0000011100 0101000000 1001100000 1111010011 1110111101 1100010101
output:
2
result:
ok 1 number(s): "2"
Subtask #2:
score: 15
Accepted
Test #7:
score: 15
Accepted
time: 1ms
memory: 4068kb
input:
20 11110010101111111000 01000101111110100000 10110001010110111101 10111111011011110101 10110101011010111101 00010100011011001011 01111111001000101001 10101101011101011100 11011010110101011110 00010100101000001011 00001010100111101100 00100111010010101001 00000010010110110110 11011111100110111100 010...
output:
2
result:
ok 1 number(s): "2"
Test #8:
score: 0
Accepted
time: 1ms
memory: 4108kb
input:
20 01000110110000100100 00010110001100011000 11111000101101101010 10010001100000010100 01101101000000111100 10010111110101011101 00000101010000000110 00001100101111111110 11111110111001101001 00010000001000101011 00010010110110110011 01011011110010011110 01000101111111011101 00010111001101001110 101...
output:
2
result:
ok 1 number(s): "2"
Test #9:
score: 0
Accepted
time: 1ms
memory: 3996kb
input:
20 00000000000000000000 10011101011010000010 10011101011010000010 10011101011010000010 10011101011010000010 10011101011010000010 10011101011010000010 10011101011010000010 10011101011010000010 10011101011010000010 10011101011010000010 10011101011010000010 10011101011010000010 10011101011010000010 100...
output:
526847
result:
ok 1 number(s): "526847"
Test #10:
score: 0
Accepted
time: 1ms
memory: 4168kb
input:
20 00000000000000000000 11101100001001010011 11101100001001010011 11101100001001010011 11101100001001010011 11101100001001010011 11101100001001010011 11101100001001010011 11101100001001010011 11101100001001010011 11101100001001010011 11101100001001010011 11101100001001010011 11101100001001010011 111...
output:
526335
result:
ok 1 number(s): "526335"
Test #11:
score: 0
Accepted
time: 1ms
memory: 3968kb
input:
20 10000000000000000000 11111000110000000000 11111000110000000000 11111000111111111111 11111000111111111111 11111000111111111111 11111000110000000000 11111000111111111111 11111000110000000000 11111000111111111111 11111000111111111111 11111000111010011011 11111000111010011011 11111000111010011011 111...
output:
740
result:
ok 1 number(s): "740"
Test #12:
score: 0
Accepted
time: 1ms
memory: 4128kb
input:
20 10000000000000000000 11110100100000000000 11110100101111111111 11110100100000000000 11110100100000000000 11110100100000000000 11110100101111111111 11110100100000000000 11110100101111111111 11110100101111111111 11110100100000000000 11110100100010000000 11110100100010000000 11110100100010000000 111...
output:
1150
result:
ok 1 number(s): "1150"
Test #13:
score: 0
Accepted
time: 1ms
memory: 4040kb
input:
20 11111111111111111111 10100111111111111111 10100100000000000000 10100100000000000000 10100111111111111111 10100100000000000000 10100100000000000000 10100111001100101111 10100111001100101111 10100111001100100000 10100111001100101111 10100111001100100000 10100111001100100000 10100111001100101111 101...
output:
189
result:
ok 1 number(s): "189"
Subtask #3:
score: 40
Accepted
Test #14:
score: 40
Accepted
time: 4ms
memory: 6852kb
input:
300 01110011110110110011100111010000101110110001000111111011100101101101101011110101110100110110001110111010101011111010010101001000100011001110110100110000111001011011100000011100000000000001101000010110110000110001110000010110100010110110111000110000100101110011111010001100110111001010000100110110...
output:
2
result:
ok 1 number(s): "2"
Test #15:
score: 0
Accepted
time: 0ms
memory: 6864kb
input:
300 00101101101001110001110111101010000101010101100001110010001101001011011110111000110110101101111100010010011111010011101011110001011011111110001110100110101010100111001110001100111011010110010010111101001001101000000000011101011000111100101000101110111011001111111000111000100111100110101001011101...
output:
2
result:
ok 1 number(s): "2"
Test #16:
score: 0
Accepted
time: 0ms
memory: 6852kb
input:
300 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
936335109
result:
ok 1 number(s): "936335109"
Test #17:
score: 0
Accepted
time: 2ms
memory: 6856kb
input:
300 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
124904823
result:
ok 1 number(s): "124904823"
Test #18:
score: 0
Accepted
time: 2ms
memory: 6840kb
input:
300 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
923149686
result:
ok 1 number(s): "923149686"
Test #19:
score: 0
Accepted
time: 2ms
memory: 6688kb
input:
300 01111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
254929271
result:
ok 1 number(s): "254929271"
Test #20:
score: 0
Accepted
time: 2ms
memory: 6860kb
input:
300 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
12177
result:
ok 1 number(s): "12177"
Subtask #4:
score: 5
Accepted
Test #21:
score: 5
Accepted
time: 794ms
memory: 126580kb
input:
5000 0000111111000001000100111100110001110111011000101000110111100011111110110011101001111001111101010001111101110011110101010011010010000000001111000111101111010010110100000110111101100000010111111110001001010100101110100010100000011100000101011011101010011111101011000110001001011010000010000101111...
output:
2
result:
ok 1 number(s): "2"
Test #22:
score: 0
Accepted
time: 815ms
memory: 126688kb
input:
5000 0010011001001111110110000001101010000101010111000001101101011100001001011101010000001111010001101001111000101001011011001000111110010001111011011101010000110000010100010110011010000110111110111100110100001010110010001011010010001001101110000000111110111111000110000011010011100001110011111010001...
output:
2
result:
ok 1 number(s): "2"
Test #23:
score: 0
Accepted
time: 802ms
memory: 126592kb
input:
5000 1100111111010100100110101001011111001111000111111010110110010101011010010001111010101001101110111111100100101111010111001111100001100101111111000010100011000110100010010110111111100001100010000111101011110111100010010000001110011110001110110001000101111010110011111001111001011011110010101000000...
output:
2
result:
ok 1 number(s): "2"
Subtask #5:
score: 35
Accepted
Test #24:
score: 35
Accepted
time: 469ms
memory: 126312kb
input:
5000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
828414647
result:
ok 1 number(s): "828414647"
Test #25:
score: 0
Accepted
time: 456ms
memory: 126452kb
input:
5000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
16621460
result:
ok 1 number(s): "16621460"
Test #26:
score: 0
Accepted
time: 822ms
memory: 126680kb
input:
5000 1010110111100100001010010010100011000101011011111111101001100001101101011001001110101011110101001110010011110111101001011010010001100100111010100100000011101101000100010001011001101100000000000000011001100101111101110010111101000000010001000101110111100011100110101001001000001101111010001111010...
output:
2
result:
ok 1 number(s): "2"
Test #27:
score: 0
Accepted
time: 516ms
memory: 126212kb
input:
5000 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
541497915
result:
ok 1 number(s): "541497915"
Test #28:
score: 0
Accepted
time: 463ms
memory: 126248kb
input:
5000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
288388087
result:
ok 1 number(s): "288388087"
Test #29:
score: 0
Accepted
time: 484ms
memory: 126272kb
input:
5000 0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
352199570
result:
ok 1 number(s): "352199570"
Test #30:
score: 0
Accepted
time: 531ms
memory: 126148kb
input:
5000 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
410201481
result:
ok 1 number(s): "410201481"
Extra Test:
score: 0
Extra Test Passed