QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#798337 | #168. Cube Dividing | CarroT1212 | RE | 1ms | 5828kb | C++14 | 1.8kb | 2024-12-04 12:26:22 | 2024-12-04 12:26:24 |
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=3e5+7;
ll n,m,nm,a,b,c,ans;
struct nod {
ll x,y,z;
bool operator == (const nod &b) const { return x==b.x&&y==b.y&&z==b.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;
vector<ll> v;
bool chk(ll x,ll y,ll z) { return 0<=x&&x<a&&0<=y&&y<b&&0<=z&&z<c; }
struct dsu {
ll f[N];
void ini(ll n) { iota(f+1,f+n+1,1); }
ll fnd(ll x) { return f[x]==x?x:f[x]=fnd(f[x]); }
void mrg(ll x,ll y) { f[fnd(x)]=fnd(y); }
} D;
void solve(ll o) {
map<pll,vector<nod>> pm;
for (ll i=1;i<=m;i++) pm[o==0?(pll){d[i].x,d[i].y}:o==1?(pll){d[i].x,d[i].z}:(pll){d[i].y,d[i].z}].pb(d[i]);
for (auto vv:pm) {
vector<nod> v=vv.se;
for (ll i=0;i+1<v.size();i++) {
ll x=mp[v[i]],y=mp[v[i+1]];
if (x>n&&y>n) D.mrg(x,y);
}
}
}
void mian() {
scanf("%lld%lld%lld%lld",&a,&b,&c,&n);
if (!n) return cout<<"0",void();
for (ll i=1;i<=n;i++) scanf("%lld%lld%lld",&d[i].x,&d[i].y,&d[i].z),mp[d[i]]=i;
nm=m=n;
for (ll i=1;i<=n;i++) {
go(d[i].x,d[i].y,d[i].z) if (chk(x,y,z)) d[++m]={x,y,z};
for (ll x:{0ll,d[i].x,a-1}) for (ll y:{0ll,d[i].y,b-1}) for (ll z:{0ll,d[i].z,c-1}) d[++m]={x,y,z};
}
sort(d+1,d+m+1),m=unique(d+1,d+m+1)-1-d;
for (ll i=1;i<=m;i++) if (!mp[d[i]]) mp[d[i]]=++nm;
D.ini(m);
for (ll o=0;o<3;o++) solve(o);
for (ll i=n+1;i<=m;i++) ans+=D.fnd(i)==i;
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: 1ms
memory: 5772kb
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: 1ms
memory: 5828kb
input:
3 3 3 1 1 1 1
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 1ms
memory: 5768kb
input:
1 1 3 2 0 0 0 0 0 2
output:
1
result:
ok single line: '1'
Test #4:
score: -100
Runtime Error
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...