http://codeforces.com/contest/202
Brand New Easy Problem
|
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; char my[5][15],ach[40][15]; int main() { int p[24][4]= { 0,1,2,3, 0,1,3,2, 0,2,1,3, 0,2,3,1, 0,3,1,2, 0,3,2,1, 1,0,2,3, 1,0,3,2, 1,2,0,3, 1,2,3,0, 1,3,0,2, 1,3,2,0, 2,0,1,3, 2,0,3,1, 2,1,0,3, 2,1,3,0, 2,3,0,1, 2,3,1,0, 3,0,1,2, 3,0,2,1, 3,1,0,2, 3,1,2,0, 3,2,0,1, 3,2,1,0 }; int n,m,k; while(scanf("%d",&n)==1) { for(int i=0;i<n;i++) scanf("%s",my[i]); scanf("%d",&m); int P=-4,ans; for(int h=1;h<=m;h++) { scanf("%d",&k); for(int i=0;i<k;i++) scanf("%s",ach[i]); if(k<n) continue; //cout<<"bug"<<endl; for(int j,i=0;i<24;i++) { j=0; for(int r=0;r<k&&j<n;r++) if(strcmp(my[p[i][j]],ach[r])==0) j++; if(j>=n) { int cnt=0; for(int i1=1;i1<4;i1++) for(int i2=0;i2<i1;i2++) if(p[i][i1]<p[i][i2]) cnt++; int tmp=n*(n-1)/2+1-cnt; if(P<tmp) P=tmp,ans=h; } } } if(P<0) puts("Brand new problem!"); else { printf("%d\n[:",ans); for(int i=0;i<P;i++) putchar('|'); puts(":]"); } } return 0; }
Clear Symmetry
|
#include<cstdio> #include<cmath> #include<iomanip> #include<cstring> #include<algorithm> #define ll long long using namespace std; ll a[1010][1010],b[1010],c[1010]; int main() { //freopen("data.in","r",stdin); //freopen("data.out","w",stdout); int n,m; scanf("%d%d",&n,&m); for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) scanf("%I64d",&a[i][j]); memset(b,0,sizeof(b)); memset(c,0,sizeof(c)); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { b[i]+=a[i][j]; c[j]+=a[i][j]; } ll ans1=-1,ans2=-1; int x,y; for(int i=0;i<=n;i++) { ll sum=0; for(int j=1;j<=n;j++) sum+=b[j]*(4*j-4*i-2)*(4*j-4*i-2); if(ans1==-1||sum<ans1) { ans1=sum; x=i; } } for(int i=0;i<=m;i++) { ll sum=0; for(int j=1;j<=m;j++) sum+=c[j]*(4*j-4*i-2)*(4*j-4*i-2); if(ans2==-1||sum<ans2) { ans2=sum; y=i; } } printf("%I64d\n%d %d\n",ans1+ans2,x,y); return 0; }
#include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #include<utility> #include<vector> #include<map> #include <iostream> #define LLD long long int #define MAX 1000000007 using namespace std; long long int dp[100006][2],dp2[100006][2],a[100006]; int n; void compute() { dp[0][0] = 0; dp[0][1] = 0; // wen standing on first platform... for(int i =1 ; i < n; i++) { if(a[i]!=1) dp[i][0] = dp[i-1][0] + a[i] - a[i]%2; else dp[i][0] = 0; dp[i][1] = dp[i-1][1] + a[i] -1 + a[i]%2; dp[i][1] = max(dp[i][1], dp[i][0]); //dp[i][1]=max(dp[i][1],dp[i-1][0]+a[i] -1 + a[i]%2); } dp2[n-1][0] = 0; dp2[n-1][1] = 0; // wen standing on last platform... for(int i=n-2 ; i>=0; i--) { if(a[i+1]!=1) dp2[i][0] = dp2[i+1][0] + a[i+1] - a[i+1]%2; else dp2[i][0] = 0; dp2[i][1] = dp2[i+1][1] + a[i+1] -1 + a[i+1]%2; dp2[i][1] = max(dp2[i][1], dp2[i][0]); //dp[i][1]=max(dp[i][1],dp[i+1][0]+a[i+1] -1 + a[i+1]%2 ); } /*for(int i=1;i<n;i++) cout<< dp[i][0] <<" "<< dp[i][1] <<endl; for(int i=0;i<n-1;i++) cout<< dp2[i][0] <<" "<< dp2[i][1] <<endl;*/ } int main() { cin>>n; for(int i=1; i < n; i++) cin>>a[i]; // i se i-1 brige.. compute(); long long int ans=0,temp; for(int i = 0 ; i < n; i++) { temp = dp[i][0] + dp2[i][1]; ans = max(ans,temp); temp = dp2[i][0] + dp[i][1]; ans = max(ans,temp); } cout << ans << endl; } /* 12 10 14 8 6 2 7 5 9 9 4 8 9 9 2 8 7 1 4 10 9 */