QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#945385 | #10243. Opieka [A] | Tx_Lcy | 0 | 17ms | 3712kb | C++14 | 2.1kb | 2025-03-20 21:08:37 | 2025-03-20 21:08:50 |
Judging History
answer
//A tree without skin will surely die.
//A man without face will be alive.
#include<bits/stdc++.h>
using namespace std;
#define mid ((l+r)>>1)
#define rep(i,j,k) for (int i=j;i<=k;++i)
#define per(i,j,k) for (int i=j;i>=k;--i)
int const N=1e5+10;
struct frac{int x,y;};
int n,L,ax,ay,lf[20],pre[20][N],nxt[20][N],len[20][N],sm[N];
string s[20];
inline bool dfs(int S,int sz){
if (S==(1<<n)-1) return 1;
pair<int,int>a1={1e9,-1},a2={1e9,-1};
rep(i,0,n-1){
if (S>>i&1) continue;
int pos=lf[sz];
rep(i,1,sz){
int r=lf[i]+ax;
if (r>pos) pos=max(pos,min(r,pre[sz-i+1][(r+ay-1)/ay]*ay));
}
if (len[i][pos/ay]*ay-(pos%ay)<ax){
pos=nxt[i][(pos+ay-1)/ay];
if (pos==-1) continue;
pos*=ay;
}
if (pos<a1.first) a1={pos,i};
else if (pos<a2.first) a2={pos,i};
}
if (a1.second!=-1){
lf[sz+1]=a1.first;
if (dfs(S|(1<<a1.second),sz+1)) return 1;
}
if (a2.second!=-1){
lf[sz+1]=a2.first;
if (dfs(S|(1<<a2.second),sz+1)) return 1;
}
return 0;
}
inline bool check(int a,int b){
ax=a,ay=b;
memset(pre,0,sizeof(pre));
memset(nxt,0,sizeof(nxt));
memset(len,0,sizeof(len));
rep(i,0,n-1){
per(j,L-1,0) len[i][j]=(s[i][j]=='.' && sm[j]>1)?len[i][j+1]+1:0;
nxt[i][L]=-1;
per(j,L-1,0) nxt[i][j]=len[i][j]*ay>=ax?j:nxt[i][j+1];
}
rep(i,0,n-1) rep(j,1,L){
pre[i][j]=sm[j-1]==i+1?j:pre[i][j-1];
if (i) pre[i][j]=max(pre[i][j],pre[i-1][j]);
}
return dfs(0,0);
}
inline void solve(){
cin>>n>>L;
rep(i,0,n-1) cin>>s[i];
rep(i,0,L-1){
sm[i]=0;
rep(j,0,n-1) sm[i]+=s[j][i]=='.';
if (!sm[i]) return cout<<"-1\n",void();
}
vector<frac>fracs;
rep(i,0,L) rep(j,1,n)
if (__gcd(i,j)==1) fracs.push_back((frac){i,j});
sort(fracs.begin(),fracs.end(),[](frac &x,frac &y){
return x.x*y.y<y.x*x.y;
});
int l=1,r=(int)fracs.size()-1,ans=0;
while (l<=r)
if (check(fracs[mid].x,fracs[mid].y)) l=(ans=mid)+1;
else r=mid-1;
cout<<fracs[ans].x<<'/'<<fracs[ans].y<<'\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int t=1;
cin>>t;
while (t--) solve();
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 1
Accepted
time: 0ms
memory: 3712kb
input:
1 1 .
output:
0/1
result:
ok single line: '0/1'
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 3712kb
input:
5 100 ....X..XXX........X.XX.X...............XX..............X....................X.....X.........XXXX.XX. ....X..X..........X.X..........X...................................X.......X..X.........X.....X....X ....X..X.....X....X.X.X................XX................X..X..................................
output:
0/1 0/1 0/1 0/1 0/1
result:
wrong answer 1st lines differ - expected: '73/4', found: '0/1'
Subtask #2:
score: 0
Wrong Answer
Test #36:
score: 0
Wrong Answer
time: 1ms
memory: 3712kb
input:
6 1000 ...XXXX.XXX..XXX......XX.XX..XXX....X...XX.X...XXXX.X.....XX.XX...XX..X.X...X..XXXXX.X...X.X.XX.XX..X........X....XXX.X..XXXXX.XX.X..X....XX..X...XXX..XXX..X.XX..X.X...XXXXX.XXXXXXX.XX..XX.X...X.XXXX.XXX..X...X.X.XX...XXX.XXX.X..X...X..XX.X....XXX.X.X.XXXX...X..XX.....X.X..XX.XX.X.XX..XX...XX...
output:
0/1 0/1 0/1 0/1 0/1 0/1
result:
wrong answer 1st lines differ - expected: '6/1', found: '0/1'
Subtask #3:
score: 0
Wrong Answer
Test #49:
score: 0
Wrong Answer
time: 0ms
memory: 3712kb
input:
7 10000 ..XXXX.XXX.X......X..XX.XX......XX.XX.X...X...X..X.XX........XXXX..X..X..X.X.XX.XX..XX..X...XXX.X.X.XXXX..X....X.X.X.X.....X..XX.XXX.X.X...XXXXX.XXX..X.XX...XX...X...X.XX.X...X.XX..X....XXX...X....XX........XXXXX...X..X....XXX...XXXX.X.X.X..XXXX....XX...X.X.XXX....XXXX.XX.X.X.XX..X.XXXXXXXXX...
output:
0/1 0/1 0/1 0/1 0/1 0/1 0/1
result:
wrong answer 1st lines differ - expected: '-1', found: '0/1'
Subtask #4:
score: 0
Wrong Answer
Test #64:
score: 0
Wrong Answer
time: 3ms
memory: 3712kb
input:
10 30000 ......................................................................................................................................................................................................................................................................................................
output:
0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1
result:
wrong answer 1st lines differ - expected: '15000/1', found: '0/1'
Subtask #5:
score: 0
Wrong Answer
Test #79:
score: 0
Wrong Answer
time: 6ms
memory: 3712kb
input:
12 50000 .XXXXXXXXXXXX.XXXXXXX.XX.X.XX....XX....XXXXX.XXXX.XX.XXXXXXXXXXXXX..XXXXX.X.XXX.XX..XXXXXX..XXX.XXXXX.XXXXXX.X.X..XXXXXXXXXXX.XX.XX.X.X.XX.XXXXXXXXXX.XXXXXXXXXX..XXX.XX.XXXXX.XXXXXX.XX.XXXX.XXXXX.XXXX.XXXX.XXXXXX.X.XX.XXX.XX.XXXX..X.X.XXXXXXXXXXXX...XXXXX.XX.XX...X.X..XXX.X...XXX..XXXXXXX.....
output:
0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1
result:
wrong output format Extra information in the output file
Subtask #6:
score: 0
Wrong Answer
Test #96:
score: 0
Wrong Answer
time: 8ms
memory: 3712kb
input:
14 60000 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX...
output:
0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1
result:
wrong answer 1st lines differ - expected: '-1', found: '0/1'
Subtask #7:
score: 0
Wrong Answer
Test #116:
score: 0
Wrong Answer
time: 10ms
memory: 3712kb
input:
15 70000 XXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXX.XX.XXXXXXXXXXXXX.XXXXXXXXXXXXX.XXXXXX.XXXXXXXXXXXXXXXXXX.X.XXXXXXXXXXX.X.XXXXXXXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXXXXXXXXX.XXXX.XXXXXXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXXXXXX.XXXXXXXXXXX.XXXXXXXXXXXX.XXXXX.XXXXXXXXXX.XXXXXXXXXXXXXXXX.XXXXX...
output:
0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1
result:
wrong output format Extra information in the output file
Subtask #8:
score: 0
Wrong Answer
Test #135:
score: 0
Wrong Answer
time: 13ms
memory: 3712kb
input:
16 80000 XX..XX..X.XXX.XX.XXX.XX...X..X..X....XX.....X........XXX.XXXX.X....X.XXXXX...X.....XX.X..XXX.X..X.XXX....XXXX...XX..X..X...X.XX..XXXX.XX.X....XX.X.XXX....XXX...X.XXXX..XXXXX..XX.XX..X.XXXXX.X..XXXX.XXXXX.X.XXX.X...XX.XXXXX..X..X....XX.....XX.X.XX..X.XXX.X..X..X....X.X..X..XX...X...XXX.X...X...
output:
0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1
result:
wrong answer 1st lines differ - expected: '-1', found: '0/1'
Subtask #9:
score: 0
Wrong Answer
Test #154:
score: 0
Wrong Answer
time: 16ms
memory: 3584kb
input:
17 90000 XXX.XX.XXXX.X..X..XX.XXX..XX.X....X..X..XXXXX.XX....X.XX.X.XXXXX.X..X....X..XX..X.X.XX.XX..X.XX..XX...X.XXXXX.......X...XX......X..XX.......XX..X.X..X.X.X.XX..X..XXX.XXXXX..XX.XX.X....X.XXX.X.X.XXXXXX..XX.XX.X....X......X..XX...X.XXX.X..XXX.XX.X..XXX.XXXXX.X.XXXX.X.X..X.XXX....X.X..XXX.XX.....
output:
0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1
result:
wrong answer 1st lines differ - expected: '13/1', found: '0/1'
Subtask #10:
score: 0
Wrong Answer
Test #172:
score: 0
Wrong Answer
time: 17ms
memory: 3584kb
input:
18 100000 .....................................................................................................................................................................................................................................................................................................
output:
0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1
result:
wrong answer 1st lines differ - expected: '50000/1', found: '0/1'