QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#798266 | #168. Cube Dividing | CarroT1212 | WA | 55ms | 11532kb | C++14 | 1.7kb | 2024-12-04 10:41:07 | 2024-12-04 10:41:16 |
Judging History
answer
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define go(xx,yy,zz) for(ll x=xx-1;x<=xx+1;x++)for(ll y=yy-1;y<=yy+1;y++)for(ll z=zz-1;z<=zz+1;z++)
using namespace std; bool MEM;
using ll=long long; using ld=long double;
using pii=pair<int,int>; using pll=pair<ll,ll>;
const int I=1e9;
const ll J=1e18,K=1e6+7,N=2e4+7;
ll n,a,b,c,vis[N],ans;
struct nod { ll x,y,z; bool operator < (const nod &b) const { return x!=b.x?x<b.x:y!=b.y?y<b.y:z<b.z; } } d[N];
map<nod,ll> mp;
map<nod,ll> pm;
vector<ll> v;
bool chk(ll x,ll y,ll z) { return 0<=x&&x<a&&0<=y&&y<b&&0<=z&&z<c; }
void dfs(nod p) {
pm.erase(p);
ll x=p.x,y=p.y,z=p.z;
#define goo(xx,yy,zz) if (chk(xx,yy,zz)&&pm.count({xx,yy,zz})) dfs({xx,yy,zz});
goo(x-1,y,z) goo(x+1,y,z)
goo(x,y-1,z) goo(x,y+1,z)
goo(x,y,z-1) goo(x,y,z+1)
}
void solve() {
queue<ll> q;
for (ll i:v) q.push(i);
while (!q.empty()) {
ll p=q.front(); q.pop();
go(d[p].x,d[p].y,d[p].z) if (chk(x,y,z)) {
if (mp.count({x,y,z})) {
ll t=mp[{x,y,z}];
if (!vis[t]) v.pb(t),vis[t]=1,q.push(t);
}
else pm[{x,y,z}]=1;
}
}
v.clear();
ans--;
while (pm.size()) ans++,dfs(pm.begin()->fi);
}
void mian() {
scanf("%lld%lld%lld%lld",&a,&b,&c,&n),ans=1;
for (ll i=1;i<=n;i++) scanf("%lld%lld%lld",&d[i].x,&d[i].y,&d[i].z),mp[d[i]]=i;
for (ll i=1;i<=n;i++) if (d[i].x==0||d[i].x==a-1||d[i].y==0||d[i].y==b-1||d[i].z==0||d[i].z==c-1) vis[i]=1,v.pb(i);
if (v.size()) solve();
for (ll i=1;i<=n;i++) if (!vis[i]) vis[i]=1,v.pb(i),solve();
cout<<ans;
}
bool ORY; int main() {
// while (1)
// int t; for (scanf("%d",&t);t--;)
mian();
cerr<<"\n"<<abs(&MEM-&ORY)/1048576<<"MB";
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3636kb
input:
2 2 2 4 0 0 0 1 1 0 1 0 1 0 1 1
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
3 3 3 1 1 1 1
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3728kb
input:
1 1 3 2 0 0 0 0 0 2
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 55ms
memory: 11532kb
input:
8 60 66 8004 4 49 31 0 38 42 0 45 22 1 19 23 1 36 47 6 9 15 7 55 18 4 24 51 4 34 31 0 31 64 5 24 23 0 48 34 6 30 12 6 41 22 3 6 51 3 43 34 4 49 39 5 31 5 3 36 63 5 37 21 4 11 55 6 53 41 6 51 56 6 42 9 4 59 55 3 30 49 5 15 32 3 59 64 5 7 32 2 42 60 3 0 27 7 5 41 3 34 45 5 39 57 3 24 36 0 16 13 1 55 3...
output:
15
result:
ok single line: '15'
Test #5:
score: -100
Wrong Answer
time: 47ms
memory: 5740kb
input:
97 26 86 6966 67 4 0 63 2 45 30 1 66 37 12 70 54 10 50 61 13 14 82 10 29 76 20 42 66 14 45 8 19 65 2 0 63 42 19 24 11 21 23 65 2 56 65 24 61 33 15 17 51 0 26 2 19 51 7 21 38 53 15 57 73 13 42 38 13 10 78 22 52 83 15 14 68 13 55 50 5 62 70 0 17 56 2 84 93 13 29 44 6 40 58 13 1 15 17 66 38 21 59 2 16 ...
output:
297
result:
wrong answer 1st lines differ - expected: '1', found: '297'