#include "koala.h"
#include <stdio.h>
#include <stdlib.h>
#include <bits/stdc++.h>
using namespace std;
/*static int N, W;
static int P[105];
static int maxQueries = 3200;
static int numQueries;
static void runGame(int F);
static void grader();
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
grader();
return 0;
}
void playRound(int *B, int *R) {
int i, j;
int S = 0;
for (i=0;i<N;++i) {
if ( !(B[i] >= 0 && B[i] <= W) ) {
printf("Invalid query.\n");
exit(0);
}
S += B[i];
}
if (S > W) {
printf("Invalid query.\n");
exit(0);
}
numQueries++;
if (numQueries > maxQueries) {
printf("Too many queries.\n");
exit(0);
}
int cache[2][205];
int num[2][205];
char taken[105][205];
for (i=0;i<205;++i) {
cache[1][i] = 0;
num[1][i] = 0;
}
for (i=0;i<N;++i) {
int v = B[i]+1;
int ii = i&1;
int o = ii^1;
for (j=0;j<=W;++j) {
cache[ii][j] = cache[o][j];
num[ii][j] = num[o][j];
taken[i][j] = 0;
}
for (j=W;j>=v;--j) {
int h = cache[o][j-v] + P[i];
int hn = num[o][j-v] + 1;
if (h > cache[ii][j] || (h == cache[ii][j] && hn > num[ii][j])) {
cache[ii][j] = h;
num[ii][j] = hn;
taken[i][j] = 1;
} else {
taken[i][j] = 0;
}
}
}
int cur = W;
for (i=N-1;i>=0;--i) {
R[i] = taken[i][cur] ? (B[i] + 1) : 0;
cur -= R[i];
}
}*/
int minValue(int N,int W){
int tab[N];
memset(tab,0,sizeof tab);
tab[0]=1;
int res[N];
playRound(tab, res);
//cout<<N<<" "<<W<<endl;
for (int i = 0; i < N; ++i)
{
//cout<<res[i]<<" ";
if (res[i]==0) return i;
}//cout<<endl;
return 0;
}
int maxValue(int N,int W) {
int tab[N];
for (int i = 0; i < N; ++i)
{
tab[i]=1;
//cout <<tab[i]<<" ";
}
int res[N];
int cnt=12;
int mx=5;
playRound(tab,res);
bool vis[N];
for (int i = 0; i < N; ++i)
{
if (res[i]>1) {
tab[i]++;
vis[i]=true;
}
else tab[i]=0;
}
playRound(tab,res);
for (int i = 0; i < N; ++i)
{
if (res[i]>2) tab[i]++;
else tab[i]=0;
}
playRound(tab,res);
for (int i = 0; i < N; ++i)
{
if (res[i]==4) tab[i]++;
}
playRound(tab,res);
int ans;
for (int i = 0; i < N; ++i)
{
if (res[i]==mx) ans=i;
}
return ans;
}
int greaterValue(int N,int W) {
return 0;
}
void allValues(int N,int W,int *P) {
return ;
}
/*static void runGame(int F) {
int i;
scanf("%d %d",&N,&W);
for (i=0;i<N;++i) {
scanf("%d",&P[i]);
}
numQueries = 0;
if (F == 1) {
printf("%d\n", minValue(N, W));
} else if (F == 2) {
printf("%d\n", maxValue(N, W));
} else if (F == 3) {
printf("%d\n", greaterValue(N, W));
} else if (F == 4) {
int userP[105];
allValues(N, W, userP);
for (i=0;i<N;i++) {
printf("%d ",userP[i]);
}
printf("\n");
}
printf("Made %d calls to playRound.\n", numQueries);
}
static void grader() {
int i;
int F, G;
scanf("%d %d",&F,&G);
for (i=0;i<G;i++) {
runGame(F);
}
}*/
Compilation message
koala.cpp: In function 'int maxValue(int, int)':
koala.cpp:105:9: warning: unused variable 'cnt' [-Wunused-variable]
105 | int cnt=12;
| ^~~
koala.cpp:108:10: warning: variable 'vis' set but not used [-Wunused-but-set-variable]
108 | bool vis[N];
| ^~~
koala.cpp:134:12: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
134 | return ans;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
208 KB |
Output is correct |
2 |
Correct |
3 ms |
316 KB |
Output is correct |
3 |
Correct |
3 ms |
316 KB |
Output is correct |
4 |
Correct |
3 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
208 KB |
Output is correct |
2 |
Correct |
10 ms |
208 KB |
Output is correct |
3 |
Correct |
10 ms |
316 KB |
Output is correct |
4 |
Correct |
10 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |