QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#332351#6310. Dining ProfessorsScanoWA 8ms3816kbC++201.4kb2024-02-19 14:42:432024-02-19 14:42:44

Judging History

你现在查看的是最新测评结果

  • [2024-02-19 14:42:44]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:3816kb
  • [2024-02-19 14:42:43]
  • 提交

answer

#include <bits/stdc++.h>

#define sz(v) v.size()
#define forn(i,n) for(int i = 0; i < n; ++i)
#define fi first
#define se second
#define el '\n'
#define all(v) v.begin(),v.end()
#define pb push_back
#define d(x) cout << #x << " : " << x << el

using namespace std;

typedef pair<int,int> ii;

int dr[] = {1,0,-1,0};
int dc[] = {0,1,0,-1};

const int nax = 1e5 + 20;
vector<int> g[nax];


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cout << setprecision(20)<< fixed;

  int n, cnt;
  cin >> n >> cnt;
  cnt = n - cnt;
  vector<int> a(n);
  vector<bool> pos(n);
  int ans = 0;
  forn(i,n){
    cin >> a[i];
    if(a[i]==1) ans += 3;
  }
  forn(i,n){
    if(!a[(i+1)%n] && !a[i] && !a[(i-1+n)%n] && cnt){
      pos[i] = 1;
      --cnt;
    }
  }
  forn(i,n){
    if(!a[(i+1)%n] && a[i] && !a[(i-1+n)%n] && cnt){
      pos[i] = 1;
      --cnt;
    }
  }
  
  forn(i,n){
    if(!pos[i] && !a[i] && !a[(i+1)%n] && cnt){
      pos[i] = 1;
      --cnt;
    }
    if(!pos[i] && !a[i] && !a[(i-1+n)%n] && cnt){
      pos[i] = 1;
      --cnt;
    }
  }
  forn(i,n){
    if(!pos[i] && (!a[(i-1+n)%n] || !a[(i+1)%n]) && cnt){
      pos[i] = 1;
      --cnt;
    }
  }
  forn(i,n){
    if(!pos[i] && cnt){
      pos[i] = 1;
      --cnt;
    }
  }
  forn(i,n){
    if(!a[i]){
      ans += (pos[i] + pos[(i+1)%n] + pos[(i-1+n)%n]);
    }
  }
  cout << ans << el;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3816kb

input:

5 2
1 0 1 0 1

output:

13

result:

ok 1 number(s): "13"

Test #2:

score: 0
Accepted
time: 8ms
memory: 3780kb

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: 0
Accepted
time: 8ms
memory: 3564kb

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:

174297

result:

ok 1 number(s): "174297"

Test #4:

score: -100
Wrong Answer
time: 8ms
memory: 3564kb

input:

100000 1825
0 0 0 1 0 0 1 1 0 0 1 0 0 1 0 0 1 1 0 0 0 1 1 1 0 1 1 1 1 0 1 0 0 0 1 0 0 0 0 1 1 1 1 1 0 0 0 0 0 1 1 0 0 1 1 1 1 0 1 0 0 1 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 1 1 0 0 0 0 0 0 1 0 1 0 1 0 0 1 0 0 1 1 0 1 1 0 1 1 0 1 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 1 0 0 1 0 1 0 1 1 0 0 1 0 0 1 1 0 0 1 0 1 1 1 ...

output:

299132

result:

wrong answer 1st numbers differ - expected: '300000', found: '299132'