Submission #344000

#TimeUsernameProblemLanguageResultExecution timeMemory
344000KWang31Longest beautiful sequence (IZhO17_subsequence)Java
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #define pb push_back using namespace std; const int MAX = 1 << 10; int main(){ int btcnt[MAX]; for(int i=0;i<MAX;i++){btcnt[i]=__builtin_popcount(i);} int N; scanf("%d",&N);int a[N]; int k[N]; for(int i=0;i<N;i++){ scanf("%d",&a[i]); } for(int i=0;i<N;i++){ scanf("%d",&k[i]); } int M[MAX][MAX][11]; int ind[MAX][MAX][11]; for(int i=0;i<MAX;i++) for(int j=0;j<MAX;j++) for(int k=0;k<11; k++) M[i][j][k]=-1; int q,z; int r=a[0]&(MAX-1); int prev[N]; int ans[N]; for(int i=0;i<N;i++) { q=a[i]>>10; r=a[i]&(MAX-1); ans[i]++; for(int j=0;j<MAX;j++) {//QUERY z=k[i]-btcnt[r&j]; if(z>=0 && z<=10 ) { //The first 10 bits have EXACTLY z bits in common if( M[q][j][z]+1>ans[i]) { ans[i]=M[q][j][z]+1; prev[i]=ind[q][j][z]; } } } //UPDATE for(int j=0;j<MAX;j++) { if(M[j][r][btcnt[j&q]]<ans[i]) { M[j][r][btcnt[j&q]]=ans[i]; ind[j][r][btcnt[j&q]]=i; } } } int mx=0; int cur=-1; for(int i=0;i<N;i++) { if(ans[i]>mx) { mx=ans[i]; cur=i; } } printf("%d\n", mx); vector<int> seq; seq.pb(cur+1); while(cur>0){ cur=prev[cur]; seq.pb(cur+1); } for (int i=mx-1; i>=0; i--){ printf("%d ", seq[i]); } return 0; }

Compilation message (stderr)

subsequence.java:1: error: illegal character: '#'
#include <bits/stdc++.h>
^
subsequence.java:1: error: class, interface, or enum expected
#include <bits/stdc++.h>
         ^
subsequence.java:3: error: illegal character: '#'
#define pb push_back
^
subsequence.java:6: error: class, interface, or enum expected
const int MAX = 1 << 10;
^
subsequence.java:8: error: class, interface, or enum expected
int main(){
^
subsequence.java:9: error: class, interface, or enum expected
	int btcnt[MAX]; for(int i=0;i<MAX;i++){btcnt[i]=__builtin_popcount(i);}
	                ^
subsequence.java:9: error: class, interface, or enum expected
	int btcnt[MAX]; for(int i=0;i<MAX;i++){btcnt[i]=__builtin_popcount(i);}
	                            ^
subsequence.java:9: error: class, interface, or enum expected
	int btcnt[MAX]; for(int i=0;i<MAX;i++){btcnt[i]=__builtin_popcount(i);}
	                                  ^
subsequence.java:9: error: class, interface, or enum expected
	int btcnt[MAX]; for(int i=0;i<MAX;i++){btcnt[i]=__builtin_popcount(i);}
	                                                                      ^
subsequence.java:12: error: class, interface, or enum expected
	scanf("%d",&N);int a[N]; int k[N];
	^
subsequence.java:12: error: class, interface, or enum expected
	scanf("%d",&N);int a[N]; int k[N];
	               ^
subsequence.java:12: error: class, interface, or enum expected
	scanf("%d",&N);int a[N]; int k[N];
	                         ^
subsequence.java:13: error: class, interface, or enum expected
	for(int i=0;i<N;i++){
	^
subsequence.java:13: error: class, interface, or enum expected
	for(int i=0;i<N;i++){
	            ^
subsequence.java:13: error: class, interface, or enum expected
	for(int i=0;i<N;i++){
	                ^
subsequence.java:15: error: class, interface, or enum expected
	}
	^
subsequence.java:16: error: class, interface, or enum expected
	for(int i=0;i<N;i++){
	            ^
subsequence.java:16: error: class, interface, or enum expected
	for(int i=0;i<N;i++){
	                ^
subsequence.java:18: error: class, interface, or enum expected
	}
	^
subsequence.java:20: error: class, interface, or enum expected
	int ind[MAX][MAX][11];
	^
subsequence.java:21: error: class, interface, or enum expected
	for(int i=0;i<MAX;i++)
	^
subsequence.java:21: error: class, interface, or enum expected
	for(int i=0;i<MAX;i++)
	            ^
subsequence.java:21: error: class, interface, or enum expected
	for(int i=0;i<MAX;i++)
	                  ^
subsequence.java:22: error: class, interface, or enum expected
		for(int j=0;j<MAX;j++)
		            ^
subsequence.java:22: error: class, interface, or enum expected
		for(int j=0;j<MAX;j++)
		                  ^
subsequence.java:23: error: class, interface, or enum expected
			for(int k=0;k<11; k++)
			            ^
subsequence.java:23: error: class, interface, or enum expected
			for(int k=0;k<11; k++)
			                  ^
subsequence.java:27: error: class, interface, or enum expected
	int q,z; int r=a[0]&(MAX-1); int prev[N]; int ans[N];
	^
subsequence.java:27: error: class, interface, or enum expected
	int q,z; int r=a[0]&(MAX-1); int prev[N]; int ans[N];
	         ^
subsequence.java:27: error: class, interface, or enum expected
	int q,z; int r=a[0]&(MAX-1); int prev[N]; int ans[N];
	                             ^
subsequence.java:27: error: class, interface, or enum expected
	int q,z; int r=a[0]&(MAX-1); int prev[N]; int ans[N];
	                                          ^
subsequence.java:28: error: class, interface, or enum expected
	for(int i=0;i<N;i++) {
	^
subsequence.java:28: error: class, interface, or enum expected
	for(int i=0;i<N;i++) {
	            ^
subsequence.java:28: error: class, interface, or enum expected
	for(int i=0;i<N;i++) {
	                ^
subsequence.java:29: error: class, interface, or enum expected
        	q=a[i]>>10; r=a[i]&(MAX-1); 
        	            ^
subsequence.java:30: error: class, interface, or enum expected
            ans[i]++;
            ^
subsequence.java:31: error: class, interface, or enum expected
        	for(int j=0;j<MAX;j++) {//QUERY
        	^
subsequence.java:31: error: class, interface, or enum expected
        	for(int j=0;j<MAX;j++) {//QUERY
        	            ^
subsequence.java:31: error: class, interface, or enum expected
        	for(int j=0;j<MAX;j++) {//QUERY
        	                  ^
subsequence.java:34: error: class, interface, or enum expected
                        if(z>=0 && z<=10 ) { //The first 10 bits have EXACTLY z bits in common
                        ^
subsequence.java:37: error: class, interface, or enum expected
                                   ans[i]=M[q][j][z]+1; prev[i]=ind[q][j][z];
                                                        ^
subsequence.java:38: error: class, interface, or enum expected
                            }
                            ^
subsequence.java:42: error: class, interface, or enum expected
        	for(int j=0;j<MAX;j++) {
        	            ^
subsequence.java:42: error: class, interface, or enum expected
        	for(int j=0;j<MAX;j++) {
        	                  ^
subsequence.java:44: error: class, interface, or enum expected
                            M[j][r][btcnt[j&q]]=ans[i]; ind[j][r][btcnt[j&q]]=i;
                                                        ^
subsequence.java:45: error: class, interface, or enum expected
                        }
                        ^
subsequence.java:48: error: class, interface, or enum expected
    int mx=0; int cur=-1;
              ^
subsequence.java:49: error: class, interface, or enum expected
    for(int i=0;i<N;i++) {
    ^
subsequence.java:49: error: class, interface, or enum expected
    for(int i=0;i<N;i++) {
                ^
subsequence.java:49: error: class, interface, or enum expected
    for(int i=0;i<N;i++) {
                    ^
subsequence.java:51: error: class, interface, or enum expected
			mx=ans[i]; cur=i;
			           ^
subsequence.java:52: error: class, interface, or enum expected
       }
       ^
subsequence.java:55: error: class, interface, or enum expected
    vector<int> seq;
    ^
subsequence.java:56: error: class, interface, or enum expected
    seq.pb(cur+1);
    ^
subsequence.java:57: error: class, interface, or enum expected
    while(cur>0){
    ^
subsequence.java:58: error: class, interface, or enum expected
		cur=prev[cur]; seq.pb(cur+1);
		               ^
subsequence.java:59: error: class, interface, or enum expected
	}
	^
subsequence.java:60: error: class, interface, or enum expected
	for (int i=mx-1; i>=0; i--){
	                 ^
subsequence.java:60: error: class, interface, or enum expected
	for (int i=mx-1; i>=0; i--){
	                       ^
subsequence.java:62: error: class, interface, or enum expected
	}
	^
subsequence.java:65: error: class, interface, or enum expected
}
^
61 errors