QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#373670 | #5202. Dominoes | InfinityNS# | WA | 20ms | 10536kb | C++20 | 4.6kb | 2024-04-01 21:43:52 | 2024-04-01 21:43:53 |
Judging History
answer
#include<bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
using namespace std;
typedef pair<int,int> pii;
const int mod=998244353;
inline int add(int x,int y){int ret=x+y;if(ret>=mod)ret-=mod;return ret;}
inline int sub(int x,int y){int ret=x-y;if(ret<0)ret+=mod;return ret;}
inline int mul(int x,int y){return ((ll)x*y)%mod;}
inline int step(int base,int pw){int ret=1;while(pw){if(pw&1)ret=mul(ret,base);base=mul(base,base);pw>>=1;}return ret;}
inline int invv(int x){return step(x,mod-2);}
const int maxn=4010;
int a[maxn/2][maxn/2];
ll nc2(ll x){
return ((x-1)*x)/2;
}
struct edge{
int a,b,f;
};
vector<edge>e;
vector<int>g[maxn];
int level[maxn],sink,source,cnt,start[maxn];
void add_edge(int a,int b){
g[a].pb(e.size());
e.pb({a,b,0});
g[b].pb(e.size());
e.pb({b,a,1});
///printf("%d %d AAA\n",a,b);
}
int bfs(){
queue<int>q;
q.push(source);
memset(level,0,sizeof(level));
level[source]=1;
while(q.size()){
int x=q.front();
q.pop();
for(int i=0;i<g[x].size();i++){
int id=g[x][i];
if(e[id].f || level[e[id].b])continue;
level[e[id].b]=level[x]+1;
q.push(e[id].b);
}
}
return level[sink];
}
int sflow(int x){
if(x==sink)return 1;
for(;start[x]<g[x].size();start[x]++){
int id=g[x][start[x]];
if(e[id].f==0 && level[x]+1==level[e[id].b]){
int tmp=sflow(e[id].b);
if(tmp){
e[id].f^=1;
e[id^1].f^=1;
return 1;
}
}
}
return 0;
}
vector<int>lside;
vector<int>vect[maxn];
int lpos[maxn],match[maxn];
ll full=0;
int nid[maxn/2][maxn/2];
int n,m;
map<int,pii>mapa;
int get_id(int x,int y){
if(nid[x][y]==0){
nid[x][y]=++cnt;
///mapa[cnt]={x,y};
}
return nid[x][y];
}
pii get_pos(int id){
return mapa[id];
}
void goflow(){
while(bfs()){
memset(start,0,sizeof(start));
int ret;
while(ret=sflow(source)){full--;}
}
for(int i=0;i<g[source].size();i++){
int id=g[source][i];
lside.pb(e[id].b);
lpos[e[id].b]=1;
}
for(int i=source+1;i<sink;i++){
for(int j=0;j<g[i].size();j++){
int id=g[i][j];
if(e[id].b==source || e[id].b==sink)continue;
if(e[id].f){
if(lpos[i]){
match[i]=e[id].b;
//printf("%d %d | %d %d | %d %d \n",get_pos(i).ff,get_pos(i).ss,get_pos(e[id].b).ff,get_pos(e[id].b).ss,i,e[id].b);
//printf("%d %d %d AA\n",e[id].a,e[id].b,e[id].f);
}
continue;
}
vect[i].pb(e[id].b);
}
}
}
void make_graph(){
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if((i+j)%2 || a[i][j]==0)continue;
for(int k=0;k<4;k++){
int idx=i+dx[k];
int idy=j+dy[k];
if(idx<1 || idy<1 || idx>n || idy>m || a[idx][idy]==0)continue;
add_edge(get_id(i,j),get_id(idx,idy));
}
}
}
source=0;
sink=++cnt;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(a[i][j]==0)continue;
if((i+j)%2)add_edge(get_id(i,j),sink);
else add_edge(source,get_id(i,j));
}
}
}
int pos[maxn];
void dfs(int x){
pos[x]=1;
for(int i=0;i<vect[x].size();i++){
int id=vect[x][i];
if(pos[id])continue;
dfs(id);
}
}
void sub_good(){
for(int i=0;i<lside.size();i++){
int id=lside[i];
memset(pos,0,sizeof(pos));
dfs(id);
for(int j=source+1;j<sink;j++){
if(lpos[j])continue;
if(j==match[id])continue;
if(pos[j])full--;
}
}
}
int main(){
///freopen("test.txt","r",stdin);
scanf("%d %d",&n,&m);
int ncnt[2]={0,0};
for(int i=1;i<=n;i++){
string s;
cin>>s;
for(int j=1;j<=m;j++){
if(s[j-1]=='.'){
a[i][j]=1;
ncnt[(i+j)%2]++;
}
else a[i][j]=0;
}
}
if(nc2(ncnt[0])+nc2(ncnt[1])>=1000000){
printf("1000000\n");
return 0;
}
full=nc2(ncnt[0]+ncnt[1]);
make_graph();
goflow();
sub_good();
printf("%lld\n",full);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5876kb
input:
3 6 ...#.. ...... #...##
output:
52
result:
ok 1 number(s): "52"
Test #2:
score: 0
Accepted
time: 0ms
memory: 5852kb
input:
2 2 .. ..
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5896kb
input:
2 2 #. #.
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 0ms
memory: 5880kb
input:
4 5 ###.. .###. .##.. #...#
output:
34
result:
ok 1 number(s): "34"
Test #5:
score: 0
Accepted
time: 1ms
memory: 5860kb
input:
11 12 .#######..## .##..#.....# #####..##.#. #..##...#... ###..#..##.. ####..###... .#....##..## .#####....## .###..###### .######...## #....##...##
output:
1674
result:
ok 1 number(s): "1674"
Test #6:
score: 0
Accepted
time: 0ms
memory: 6216kb
input:
50 45 ####...#.#####..#..#.#########.##.#####..#..# ##.#.....#..#####....##..###...##.....##....# ##.#...####.##.#..#...####.#....##.###....... ...#...#..#..#.##.######...##..#...###..####. ##.....#.###.####.###..#....##..##..##.###... ..#.##.......##...##.........#..##.###.###... ###..##.###...###....
output:
496312
result:
ok 1 number(s): "496312"
Test #7:
score: 0
Accepted
time: 6ms
memory: 6196kb
input:
34 65 ...............#####.#..##..############.....###....#..########## .........#......#.......##..############.##..##........########## ..............#.......#.....##########..............##.########## ...##............#..............######.......#......#..########## ......#....#.....##......#.......
output:
279744
result:
ok 1 number(s): "279744"
Test #8:
score: 0
Accepted
time: 16ms
memory: 6228kb
input:
44 44 ............................................ ............................................ ............................................ ............................................ ............................................ ............................................ ...........................
output:
936056
result:
ok 1 number(s): "936056"
Test #9:
score: 0
Accepted
time: 20ms
memory: 6516kb
input:
45 45 ............................................. ............................................. ............................................. ............................................. ............................................. ............................................. .....................
output:
999000
result:
ok 1 number(s): "999000"
Test #10:
score: 0
Accepted
time: 11ms
memory: 8416kb
input:
59 59 ...#.......#.......#...#...#...................#........... .#.#.#####.#.#####.#.#.#.#.#.#################.#.#########. .#.#.#.....#.#...#.#.#.#.#.#.#...............#.#.#...#...#. .#.#.#.#####.#.#.#.#.#.#.#.#.#.#############.#.#.#.#.#.#.#. .#.#.#.#...#.#.#.#...#...#...#.#...#.........#...#.#.#...
output:
809100
result:
ok 1 number(s): "809100"
Test #11:
score: 0
Accepted
time: 18ms
memory: 8640kb
input:
39 99 ...#.......#...#...................#...#...#...#...#...........#...#.......#....................... .#.#.#####.#.#.#.#################.#.#.#.#.#.#.#.#.#.#########.#.#.#.#####.#.#####################. .#.#.....#.#.#.#.........#.........#.#.#.#.#.#.#.#.#.#...#.....#.#.#.#.....#.....#.......#...#...
output:
999000
result:
ok 1 number(s): "999000"
Test #12:
score: 0
Accepted
time: 15ms
memory: 10536kb
input:
99 39 .......#.......#....................... .#####.#.#####.#.#####################. .....#.#.....#.#.#.......#............. ####.#.#####.#.#.#.#####.#.############ .....#.#.....#...#.#.....#.#........... .#####.#.#########.#.#####.#.#########. .....#.#.....#...#.#.....#.#.....#..... ####.#.#####.#...
output:
999000
result:
ok 1 number(s): "999000"
Test #13:
score: 0
Accepted
time: 15ms
memory: 6264kb
input:
45 45 #.......................................###.. .........................................##.. ............................................. ............................................. ............................................. ............................................. .....................
output:
999000
result:
ok 1 number(s): "999000"
Test #14:
score: -100
Wrong Answer
time: 5ms
memory: 6820kb
input:
132 453 ###########################################################..####################..###################################################################.#################################################..############################..############################################################...
output:
1997915
result:
wrong answer 1st numbers differ - expected: '1000000', found: '1997915'