509 - RAID!

All about problems in Volume 5. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
cksteven
New poster
Posts: 5
Joined: Wed Jul 23, 2014 9:38 am

509 - RAID!

Post by cksteven » Wed Jul 23, 2014 9:50 am

Here is my code.
I tested the sample input and the output was right on my machine.
Can someone kind help find my mistake or offer me some test i/o,plz?
Or someone can plz post your AC code so that i can learn from you?
I'm confused with this problem for a whole day.

Code: Select all

#include<stdio.h>
#include<string.h>
#define maxn 65000
#define maxd 8
char raid[maxd][maxn];
char data[maxn];

int check(int b,int s,int d,int parity){
	for(int i=0;i<b;i++)
				for(int j=0;j<s;j++){
					int sum=0,tot=0;
					for(int k=0;k<d;k++)
						if(raid[k][s*i+j]=='x')
							{if(k%d==i%d) return 0;
							else tot++;}
						else sum+=raid[k][s*i+j]-'0';
					if(tot>1) return 0;
					if(tot==0&&sum%2!=parity) return 0;
					for(int k=0;k<d;k++)
						if(raid[k][s*i+j]=='x'){
							if(sum%2!=parity) raid[k][s*i+j]='1';
							else raid[k][s*i+j]='0';
						}
				}
}
int main(){
#ifdef LOCAL
	freopen("input.txt","r",stdin);
#endif
	int d,s,b,kase=0;
	while(scanf("%d%d%d\n",&d,&s,&b)==3&&d){
		//INIT
		memset(raid,'\0',sizeof(raid));
		memset(data,'\0',sizeof(data));
		int parity;
		scanf("%c\n",&parity);
		if(parity=='O') parity=1;
		else parity=0;
		for(int i=0;i<d;i++)
			scanf("%s",raid[i]);
		//CHECK
		int valid=check(b,s,d,parity);
		//OUTPUT
		printf("Disk set %d is ",++kase);
		if(valid){
				printf("valid, contents are: ");
			for(int i=0;i<b;i++)
				for(int j=0;j<d;j++)
					for(int k=0;k<s;k++){
						//printf("\n %d %d\n",j%d,i%d);
						if(j%d!=i%d) sprintf(data,"%s%c",data,raid[j][s*i+k]);}
			while(strlen(data)%4) sprintf(data,"%s%c",data,'0');
			for(int i=0;i<strlen(data)/4;i++){
				int x=0;
				for(int j=0;j<4;j++) x+=(data[i*4+3-j]-'0')<<j;
				printf("%X",x);
			}
			printf("\n");
			//printf("%s\n",data);
			//for(int i=0;i<d;i++)
			//	printf("%s\n",raid[i]);
		}else printf("invalid.\n");
	}
	return 0;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 509 - RAID! WA

Post by brianfry713 » Wed Jul 23, 2014 7:58 pm

Input:

Code: Select all

3 62 34
O
10000010010110100010101010101010010111101010000001110001011101100010110011011100011011111101011011010011100110111000011101001110011001111000011001001011110001110010110010010010100001010000111111010011000000010000101101010100001000110010000000000110111111110000111111011011011011000111011011100000101001000101001111010101010110110010110010110101010000111101110111111110101110011111110100001011110001001011000110001111111111010010100000100011011101000010111110100000000001101011111010001110110011011111001100101001101011100101010101001101111111001110001011100110001111110001000111001100000110100011100110110100000110100010000011100001010100101110100001000001101101000010100011010110011011101101000111100001100111000101000010110101101101010111011100000001000111001011100111110000011011101011111011111100111100001110000001111010101000011001000111101000111011111011000001101111001001000101010000100000100011101000100110100100110111101110000010000000010000001111011100111010010110111100100011110101100001000111100110101110000110010010101110001010101010000010111110000111110011100001011010001100000011000010100101100001110000100111111110100000110111000010001010101100110010001111001000010110110000010111100111011110011010001111111100100111010001001110110101001111001010001000000111101111101011111101101101101110100000110111001111011101010101110010011000100010101011000010110111110010000110100011111111100101110101001010001000011100000010100100000000010111110011011100111111111011000010111010100010001100010111111101110111101100111101110100111011101110111001100011100100110111011101010100010111000010011000101100001011010101001001010110010100100101001111000000111101100100010000010100000000111000110110110110111001010010000010000001110111101101000000110111110110001010011101000110101110101101101011110000100111001100011101011010101101100111110010111001110011100010000010101110101000111110100111111010001100010100111010001010101000100000000010011110100001000100111011011010011001001101011000101001100010011010100010111100110010100001001100110111011101110111111011111000101111110010101100011110011110100101011010000110
11010110011011010000110010001100001001000001110110110111101010000000111111000010001010000100100000011100100101111010110110101101011101010010001111000011110000101000001000001000100101110111111111111010100000010001110000101010000101111011010111010011001100000000110111001110011010100011011011111100000111010100010001101110001111010011011001000010001110100111010001000101011010111000000010111101101110011010000100000001011011101110101000001001100100110011101010000100111011001001010011100001100110001111011111010101011001011000001010111000011001001111110010111010000110111011010111000001010110010001010000101110010011110010011010011011011000011110010011010011010100101001110000101100011010110100110001010010000110111010101100111101000000010000101001111001011011111001000011001001111001001100001101000101011111001101101010010100110100001110010111001001000011000010010001010101011111011111011011010011100110111000011100001000100101011000111000101011101001111101010010000010000101011101010101000001010011011001001111110100000001000011110000100011100100100010110111001001011000111111101100111100100000100000011100011001011011000100111111111111111011001100000010111000101010000111011101100111100001011000000011010110101100010100001101111110110111001111111101101010001100010001101010001110000110110000101100010100100010010101100101011100101011001010011100010110010100101100001000011000001010011010100010000100101101100001111010000000010000100011001000111000001111110101111110010010010110100011001011100011001000101111101110110011111110000100010101010111100101010100000000100110100111011001110000000010000010100111010111010010011010110101110101101110011010111010000000111111101010001000011010011011010101011111101001001100010111000011000110010110100011010001001011111000011001011010100100101010101001100001100010100100111010010111101110000111100110101010011111001110101010100111101010110001101100110011011000101100111100010100000001010111011101111011010111111111110110011101110011101110001100110101110000111010100001000100011001100101100000010100001001000100110101011111110100011111001011000100001110001000101010110010
10101011110010001101100111011001100001010100001000111001001000011101110011100001101110000110000100110000111100111101010100011100111011010101101001110111111110100101000101100101111011011000111111010110011111111110100010000001110010110110101000101010001100001111110111101010111110011011111111100011010001101110100001000100100110011110010100001000100001100101011001000100001011011000001001001001100000101110111101110001011011000011110111010101000110001110101011011011000101011101010110010000101010101111101100000011001101000010100000001010011001111110000110100011110110110101101111110010101111001101001001100101101010101111100110000101110011001111001101101101000110010100101100000101111110100110001001001100011110000000010001110111010010111000001010000111100011001101011011000110011101011000001001000110011100111100010100010001100011101000101111011110000111000110101111000101101001100101110100001100111010101111000101010011101101001001000101010100000110001101110001000111101100011110001001001011001101100001010110100101111000101110100001010110110001011111110110110001010100100001001001001111011100011101000110000111010100011100111110100000110011110001110111101011100111110111101010001110101110110000011011110111001001100100001110100110011001111110110111011010111001100110010010011110010010110010111110000101111101011101010101111110000001000111111011001011000000010001000000010101110011000110100010011110100111010100001101100011101101111000110111010000000011010110111110010110101011100110010110010000100000101101100110100000111100001111010001000110100011001000011011101110000101110010011000111111100101110100100011111000101100011100011110110100101010000101000010100100000101100011100101011100011100010110101111100001101010111101001110000100011100011001000010001101111011100011110101111000111101101110111010010111011000110010111100011111101011101100010011010011010111110110111101110000110100110110101011000111111001100001010110001000100000011010001001000100110010111000010101011100101011100011101101011111111100000111010100111011010011011100101011001100110001011000100100010010011000100101101111010010001111001011
0
AC output:

Code: Select all

Disk set 1 is valid, contents are: D66D0C8C241DB7AAAF2367661508E488B371BF5B4E6E1D1DCE1B86130F3D51E67864BC72C928535D48F0F0A08225DFFEA0470A85ED74CFD67FE881CB6A2AFF0FDB6C76E0A450C3F7ABE6FF8D1BAF556CB2D50F77FAC6E3D36423A74456B80BDB9A1016EEA3609260BBDC5B0F78DD0BE801AFA3B35518EADB15D590AAF329AE554DFCE2E7DF55960AE193F2E86ED7056450B93CBDB5BF2BCD265AAF0E152E841B428D6661733CDB4652C17BB47867142D6D5DEB4C521BAB3D010A796F90C9E4C3457E1E335B19D60919C381EA8647A3BEC1BC5118E8BDE1C6BCF2454208E89A4DED5F7DB4E6E1C225638AE9F520857550515418DC47B1E24B8479AE192B8AA82CD856978BA15B17FE1F385A3030A5871C963FB3C8207196C4FFFECC0B8A877473E833C77AE7DEA5B05E779A3FC9D10EBB06F72643A667ED4F2881EFAFDB6FFDA8C46A386C2C52256572B29C594B1F5D57E047ECB011DF21A3FE5D4A21C005731A27A750D8E29005F373FEC2EA0232383F5F925A32E322FBB3F8455796420B6683C3D11A38E4DDD517098B0B486EE17263F9748F52565253C0F644149AD75B9AE80FEA21A6D57E93170C65B95C716BE1ABD384037D8A746BADAF09C64237B8F5E3DBB731D6AD9F2E73880A4E97B879AA7CEAA7AB1B3362CF1407DBDC34DAB1F98568027A113B6993588881A244CB855CAE989A8BCCA133777570EA11199605091357F47CB10E22AC8C58912625BD23CB
Check input and AC output for thousands of problems on uDebug!

cksteven
New poster
Posts: 5
Joined: Wed Jul 23, 2014 9:38 am

Re: 509 - RAID! WA

Post by cksteven » Thu Jul 24, 2014 1:49 am

Thank you brianfry713.
Finally i got AC.
But the mistake is that if a parity block is broken but the data blocks are still available, the disk is still vaild, not invalid.
(english may be not 100% appropriate)

Post Reply

Return to “Volume 5 (500-599)”