QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#768304 | #6310. Dining Professors | Wsy | WA | 6ms | 4760kb | C++23 | 1014b | 2024-11-21 08:52:22 | 2024-11-21 08:52:22 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
int n,m,cnt,ans;
int a[maxn];
bool flag[maxn];
int main() {
scanf("%d%d",&n,&m);
m=n-m;
for (int i=1;i<=n;i++) {
scanf("%d",&a[i]);
if (a[i]) ans+=3;
a[i+n]=a[i];
}
for (int i=1;i<=n;i++) {
if (!a[i] && !a[i+1] && !a[i+2]) flag[i+1]=1,ans+=3,cnt++;
}
if (flag[n+1]) flag[1]=1;
if (cnt>=m) {
printf("%d\n",ans);
return 0;
}
for (int i=1;i<=n;i++) {
if (flag[i+1]) continue;
int s=0;
if (!a[i]) s++;
if (!a[i+1]) s++;
if (!a[i+2]) s++;
if (s==2) {
flag[i+1]=1;
ans+=2;
cnt++;
if (cnt==m) {
printf("%d\n",ans);
return 0;
}
}
}
if (flag[n+1]) flag[1]=1;
for (int i=1;i<=n;i++) {
if (flag[i+1]) continue;
int s=0;
if (!a[i]) s++;
if (!a[i+1]) s++;
if (!a[i+2]) s++;
if (s==1) {
flag[i+1]=1;
ans++;
cnt++;
if (cnt==m) {
printf("%d\n",ans);
return 0;
}
}
}
printf("%d\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3904kb
input:
5 2 1 0 1 0 1
output:
13
result:
ok 1 number(s): "13"
Test #2:
score: 0
Accepted
time: 6ms
memory: 4608kb
input:
100000 33292 1 1 1 1 0 1 1 0 0 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 0 1 1 1 0 1 0 0 1 1 0 0 0 1 0 1 0 1 0 1 1 0 1 1 1 1 0 1 1 0 1 1 1 0 1 0 0 0 1 0 0 0 1 0 0 1 0 0 0 1 0 0 0 0 0 0 0 1 1 0 0 1 1 1 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 1 0 1 0 1 0 1 1 1 1 0 1 0 0 0 0 0 1 1 0 1 0 1 0 1 1 1 0 0...
output:
279236
result:
ok 1 number(s): "279236"
Test #3:
score: -100
Wrong Answer
time: 3ms
memory: 4760kb
input:
100000 91906 1 1 1 1 1 0 1 0 0 0 1 0 0 0 1 0 1 1 1 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 1 0 1 0 0 0 1 0 0 1 0 1 0 0 1 1 1 0 0 1 0 0 0 1 1 1 0 0 0 1 0 1 1 0 1 0 0 1 1 0 1 0 1 0 1 1 0 0 0 1 0 0 1 0 1 0 1 1 1 0 1 0 1 1 1 0 1 1 0 0 0 0 1 1 1 1 1 1 1 0 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0...
output:
187545
result:
wrong answer 1st numbers differ - expected: '174297', found: '187545'