結果

問題 No.332 数列をプレゼントに
ユーザー LayCurseLayCurse
提出日時 2015-12-25 00:37:55
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 3,889 bytes
コンパイル時間 2,892 ms
コンパイル使用メモリ 162,664 KB
実行使用メモリ 185,632 KB
最終ジャッジ日時 2023-10-19 03:06:30
合計ジャッジ時間 14,347 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 25 ms
92,728 KB
testcase_02 WA -
testcase_03 AC 22 ms
92,184 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 196 ms
157,192 KB
testcase_08 WA -
testcase_09 AC 46 ms
97,252 KB
testcase_10 AC 68 ms
103,836 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 201 ms
184,204 KB
testcase_25 AC 203 ms
185,464 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 204 ms
182,160 KB
testcase_29 AC 211 ms
182,160 KB
testcase_30 WA -
testcase_31 AC 212 ms
179,524 KB
testcase_32 AC 197 ms
179,524 KB
testcase_33 AC 198 ms
179,524 KB
testcase_34 AC 199 ms
185,632 KB
testcase_35 AC 199 ms
185,632 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 210 ms
182,496 KB
testcase_39 WA -
testcase_40 AC 214 ms
182,496 KB
testcase_41 AC 213 ms
182,496 KB
testcase_42 AC 207 ms
179,544 KB
testcase_43 AC 211 ms
179,544 KB
testcase_44 WA -
testcase_45 AC 199 ms
179,544 KB
testcase_46 AC 108 ms
151,808 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void reader(double*)’:
main.cpp:15:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 | void reader(double *x){scanf("%lf",x);}
      |                        ~~~~~^~~~~~~~~
main.cpp: In function ‘int solve(int, int*)’:
main.cpp:60:39: warning: iteration 10 invokes undefined behavior [-Waggressive-loop-optimizations]
   60 |     rep(k,50) j[k] = ((j[k]-A[i])%md[k]+md[k])%md[k];
      |                                   ~~~~^
main.cpp:4:29: note: within this loop
    4 | #define REP(i,a,b) for(i=a;i<b;i++)
      |                             ^
main.cpp:5:18: note: in expansion of macro ‘REP’
    5 | #define rep(i,n) REP(i,0,n)
      |                  ^~~
main.cpp:60:5: note: in expansion of macro ‘rep’
   60 |     rep(k,50) j[k] = ((j[k]-A[i])%md[k]+md[k])%md[k];
      |     ^~~
main.cpp:62:38: warning: iteration 10 invokes undefined behavior [-Waggressive-loop-optimizations]
   62 |     rep(k,50) j[k] = (j[k]+A[i])%md[k];
      |                                  ~~~~^
main.cpp:4:29: note: within this loop
    4 | #define REP(i,a,b) for(i=a;i<b;i++)
      |                             ^
main.cpp:5:18: note: in expansion of macro ‘REP’
    5 | #define rep(i,n) REP(i,0,n)
      |                  ^~~
main.cpp:62:5: note: in expansion of macro ‘rep’
   62 |     rep(k,50) j[k] = (j[k]+A[i])%md[k];
      |     ^~~
main.cpp: In function ‘int main()’:
main.cpp:80:14: warning: iteration 10 invokes undefined behavior [-Waggressive-loop-optimizations]
   80 |     md[loop] = p[(ps/2)+rand()%(ps/2)];
      |     ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:4:29: note: within this loop
    4 | #define REP(i,a,b) for(i=a;i<b;i++)
      |                             ^
main.cpp:5:18: note: in expansion of macro ‘REP’
    5 | #define rep(i,n) REP(i,0,n)
      |                  ^~~
main.cpp:79:3: note: in expansion of macro ‘rep’
   

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)

#define ll long long
#define ull unsigned ll

void reader(int *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
void reader(ll *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
void reader(double *x){scanf("%lf",x);}
int reader(char c[]){int i,s=0;for(;;){mygc(i);if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF) break;}c[s++]=i;for(;;){mygc(i);if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF) break;c[s++]=i;}c[s]='\0';return s;}
template <class T, class S> void reader(T *x, S *y){reader(x);reader(y);}
template <class T, class S, class U> void reader(T *x, S *y, U *z){reader(x);reader(y);reader(z);}
template <class T, class S, class U, class V> void reader(T *x, S *y, U *z, V *w){reader(x);reader(y);reader(z);reader(w);}

void writer(int x, char c){int s=0,m=0;char f[10];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
void writer(ll x, char c){int s=0,m=0;char f[20];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
void writer(double x, char c){printf("%.15f",x);mypc(c);}
void writer(const char c[]){int i;for(i=0;c[i]!='\0';i++)mypc(c[i]);}
void writer(const char x[], char c){int i;for(i=0;x[i]!='\0';i++)mypc(x[i]);mypc(c);}
template<class T> void writerLn(T x){writer(x,'\n');}
template<class T, class S> void writerLn(T x, S y){writer(x,' ');writer(y,'\n');}
template<class T, class S, class U> void writerLn(T x, S y, U z){writer(x,' ');writer(y,' ');writer(z,'\n');}
template<class T> void writerArr(T x[], int n){int i;if(!n){mypc('\n');return;}rep(i,n-1)writer(x[i],' ');writer(x[n-1],'\n');}

char memarr[17000000]; void *mem = memarr;
#define MD 1000000007

int getPrime(int N, int res[]){int i,a,b,s=1,f[4780],S=1;const int r=23000;bool B[r],*p=B;N/=2;res[0]=2;b=min(r,N);REP(i,1,b)p[i]=1;REP(i,1,b)if(p[i]){res[s++]=2*i+1;f[S]=2*i*(i+1);if(f[S]<N){for(;f[S]<r;f[S]+=res[S])p[f[S]]=0;S++;}}for(a=r;a<N;a+=r){b=min(a+r,N);p-=r;REP(i,a,b)p[i]=1;REP(i,1,S)for(;f[i]<b;f[i]+=res[i])p[f[i]]=0;REP(i,a,b)if(p[i])res[s++]=2*i+1;}return s;}

int N, A[120];
ll X;
int ps, p[100000], md[10];

int dp[50][120][10000];
int res[120];

int solve(int i, int j[]){
  int k, ok;
  ll chk;

  if(i==-1){
    chk = 0;
    rep(k,N) if(res[k]) chk += A[k];
    if(chk==X) return 1;
    return 0;
  }

  if(solve(i-1, j)) return 1;

  ok = 1;
  rep(k,50) if(j[k]==A[i]%md[k] || dp[k][i][((j[k]-A[i])%md[k]+md[k])%md[k]]); else {ok = 0; break;}
  if(ok){
    res[i] = 1;
    rep(k,50) j[k] = ((j[k]-A[i])%md[k]+md[k])%md[k];
    if(solve(i-1, j)) return 1;
    rep(k,50) j[k] = (j[k]+A[i])%md[k];
    res[i] = 0;
  }

  return 0;
}

int main(){
  int i, j, k, tar[10], loop;
  ll chk;

  reader(&N,&X);
  rep(i,N) reader(A+i);

  ps = getPrime(6000, p);
  srand(time(NULL));

  rep(loop,50){
    md[loop] = p[(ps/2)+rand()%(ps/2)];

    tar[loop] = X % md[loop];
    rep(i,N+1) rep(j,md[loop]) dp[loop][i][j] = 0;
    rep(i,N){
      dp[loop][i+1][A[i]%md[loop]] = 1;
      rep(j,md[loop]) dp[loop][i+1][(j+A[i])%md[loop]] |= dp[loop][i][j];
      rep(j,md[loop]) dp[loop][i+1][j] |= dp[loop][i][j];
    }

//    writerLn(tar);
//    rep(i,N+1) rep(j,md) if(dp[i][j]) printf("%d %d %d\n",i,j,dp[i][j]);
//    puts("");

  }

  rep(k,50) if(dp[k][N][tar[k]]==0) break;
  if(k==50){
    rep(i,N) res[i] = 0;
    k = solve(N-1, tar);
    if(k){
      rep(i,N) mypc(res[i]?'o':'x');
      mypc('\n');
      return 0;
    }
  }

  writerLn("No");

  return 0;
}
0