QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#518195 | #9132. Painting Fences | stonejjun | WA | 16ms | 50924kb | C++17 | 1.7kb | 2024-08-13 17:48:09 | 2024-08-13 17:48:10 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double dl;
typedef pair<dl,dl> pdi;
typedef pair<ll,ll> pii;
typedef pair<ll,pii> piii;
#define ff first
#define ss second
#define eb emplace_back
#define ep emplace
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define compress(v) sort(all(v)), v.erase(unique(all(v)), v.end())
#define IDX(v, x) lower_bound(all(v), x) - v.begin()
//cout<<fixed;
//cout.precision(12);
vector<ll> arr[1010101];
vector<ll> u[1010101];
ll n,m;
string s;
stack<pii> st;
ll inf=1e18;
ll calc(ll a,ll b,ll c){
if(b==0) return inf;
ll cnt=0;
ll x=b;
while(x<a+b){
x*=2;
cnt++;
}
if(a%b){
x-=b-(a%b);
}
while(x<a+b+c){
x*=2;
cnt++;
}
//cout<<a<<' '<<b<<' '<<c<<' '<<cnt<<'\n';
return cnt;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin>>n>>m;
for(ll i=0;i<=n;i++){
arr[i].resize(m+3);
}
ll ans=inf;
for(ll i=1;i<=n;i++){
cin>>s;
//cout<<i<<' '<<s<<endl;
for(ll j=1;j<=m;j++){
if(s[j-1]=='1')
arr[i][j]=arr[i-1][j]+1;
}
//cout<<i<<' '<<s<<endl;
for(ll j=1;j<=m+1;j++){
while(st.size()&&st.top().ff>=arr[i][j]){
ll x=calc(i-st.top().ff,st.top().ff,n-i);
ll y=calc(st.top().ss-1,j-st.top().ss,m-j+1);
st.pop();
ans=min(ans,x+y);
}
st.push({arr[i][j],j});
}
while(st.size()) st.pop();
}
cout<<ans;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 7ms
memory: 50924kb
input:
4 4 1001 0100 0110 0110
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: -100
Wrong Answer
time: 16ms
memory: 50924kb
input:
3 3 000 111 111
output:
3
result:
wrong answer 1st numbers differ - expected: '1', found: '3'