QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#743157#6310. Dining Professorswuya#WA 5ms5192kbC++172.1kb2024-11-13 18:25:062024-11-13 18:25:07

Judging History

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

  • [2024-11-13 18:25:07]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:5192kb
  • [2024-11-13 18:25:06]
  • 提交

answer

// #pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define IOS                      \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);
#define pb push_back
#define st first
#define nd second
#define PII pair<ll, ll>
#define D(x, y) cout << x << "=" << y << endl;
#define fcout(x, n) cout << fixed << setprecision(x) << n << endl;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rep2(i, a, b) for (int i = a; i >= b; i--)
// #define int long long
typedef long long ll;
typedef unsigned long long ull;
const ll inf = 0x3f3f3f3f;
const int N = 1e5 + 10;
const int M = 1e9+7;
inline ll rd()
{
    ll x = 0;
    bool f = 1;
    char c = getchar();
    for (; !isdigit(c); c = getchar())
        if (c == '-') f = 0;
    for (; isdigit(c); c = getchar())
        x = (x << 3) + (x << 1) + c - '0';
    return f ? x : 0 - x;
}
inline void out(ll x)
{
    if (x < 0) putchar('-'), x = -x;
    if (x > 9) out(x / 10);
    putchar(x % 10 + '0');
}
// __int128 rd()
// {
// 	char arr[30];
// 	__int128 res = 0;
// 	scanf("%s", arr);
// 	for (int i = 1; i <= strlen(arr); i++)
// 	{
// 		res *= 10;
// 		res += arr[i]-'0';
// 	}
// 	return res;
// }
// void pt(__int128 num)
// {
// 	if (num > 9) pt(num / 10);
// 	putchar(num % 10 + '0');
// }

ll n, m;
ll a[N],s[N],sum[4];
void solve()
{
    cin>>n>>m;
    rep(i,1,n+1) 
    {
        cin>>a[i];
        if(a[i]==0) s[i-1]++,s[i]++,s[i+1]++;
    }
    s[1]+=s[n+1];s[n]+=s[0];
    rep(i,1,n+1) sum[s[i]]++;
    ll m1=0;
    rep(i,1,4) m1+=sum[i];
    if(n-m1>=m) return cout<<3*n<<endl,void();
    m-=n-m1;
    ll ans=3*n;
    rep(i,1,4)
    {
        if(m>=sum[i])
        {
            ans-=sum[i]*i;
        }
        else 
        {
            ans-=m*i;
            break;
        }
    }
    cout<<ans<<endl;
}
signed main()
{
    IOS
        // freopen("../.vscode/io/in.txt","r",stdin),freopen("../.vscode/io/out.txt","w",stdout);
        ll T = 1;
    // cin >> T;
    while (T--)
        solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 2
1 0 1 0 1

output:

13

result:

ok 1 number(s): "13"

Test #2:

score: 0
Accepted
time: 5ms
memory: 5076kb

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: 2ms
memory: 5192kb

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:

150015

result:

wrong answer 1st numbers differ - expected: '174297', found: '150015'