Submission details
Task:Tontti
Sender:hello_world
Submission time:2015-10-01 16:56:04 +0300
Language:C++
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.04 s1details
#20.06 s1details
#30.06 s1details
#40.06 s1details
#50.06 s1details
#60.05 s2details
#70.05 s2details
#80.05 s2details
#90.05 s2details
#100.06 s2details
#110.06 s3details
#120.06 s3details
#130.06 s3details
#140.06 s3details
#150.07 s3details

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:31:15: warning: unused variable 'lines' [-Wunused-variable]
  unsigned int lines = 0; //montako lineä on muistissa
               ^
input/code.cpp:42:31: warning: ignoring return value of 'char* fgets(char*, int, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   fgets(char_line, len, stdin);
                               ^

Code

#include <stdio.h>
#include <iostream>
#include <string>
#include <string.h>
#include <stdlib.h>

using namespace std;

struct Line{
	unsigned int *trees;
	Line *next;
	Line *last;
};

void printTrees(Line *a, unsigned int w);

int main(void){
	
	unsigned int h, w, x;	//korkeus, leveys, puiden määrä aluetta kohti
	
	cin >> h;	//korkes
	cin >> w;	//leveys
	cin >> x;	//puita / alue (voi olla myös nolla, ota se huomioon)

	Line *a = (Line *)malloc(sizeof(Line));
	a->next = NULL;
	a->last = NULL;
	a->trees = (unsigned int *)malloc(sizeof(unsigned int) * w);

	Line *ap = a;
	unsigned int lines = 0;	//montako lineä on muistissa
	unsigned int len = w + 1;
	char *char_line = (char*)malloc(sizeof(unsigned int) * len);


	if (!feof(stdin)) fgetc(stdin);
	
	unsigned int i = h;
	
	while(i--) {
		cout << "i:" << i << " " << char_line << endl;
		fgets(char_line, len, stdin);
		fgetc(stdin);
		
		//katsotaan montako puuta uudella linellä oli, muodostetaan uusi Line
		unsigned int j = w;
		unsigned int tree_count = 0;
		
		while(j--){
			if (char_line[j] == '*') {
				tree_count++;
			}
			ap->trees[j] = tree_count;	//rivin alkiosta[ind] rivin loppuun olevien puiden määrä
		}
		
		//lasketaan neliöt
		/*unsigned int v = w;
			cout << "a->";
			while(v--){
				cout << ap->trees[v] << " " << endl; 
			}*/
		//katsotaan onko lines tarpeeksi suuri, jotta voidaan alkaa muodostamaan neliön muotoisia
		
		if (i) {	//muodostetaan uusi line, mikäli tarvetta, eli linejen ottamista jatketaan vielä
			ap->next = (Line *)malloc(sizeof(Line));
			(ap->next)->last = ap;
			ap = ap->next;
			ap->trees = (unsigned int *)malloc(sizeof(unsigned int) * w);
		}
		
		//nyt on uusi line jälleen alustettu(ja kenties vanha poistettu)
		
	}
	
	//nyt on kaikki linet tallessa
	
	//printTrees(ap, w);

	
	free(char_line);

	return 0;
	
}

void printTrees(Line *ap, unsigned int w){
	Line *l = ap;
	while(l != NULL) {
		unsigned int w2 = w;
		cout << "line: ";
		while (w2--){
			cout << l->trees[w2] << " ";
		} cout << endl;
		l = l->last;
		cin.get();
	}
}

void freeMemory(Line *line){
	Line *l;
	do {
		l = line;
		line = line->last;
		free(l->trees);
		free(l);
	} while(line->last != NULL);
}

Test details

Test 1

Group: 1

Verdict:

input
10 10 1
......*...
.......*..
*..*....*.
*....*....
...

correct output
94

user output
i:9 
i:8 ......*...
i:7 .......*..
i:6 *..*....*.
i:5 *....*....
...

Test 2

Group: 1

Verdict:

input
10 10 5
**********
**********
**********
**********
...

correct output
0

user output
i:9 
i:8 **********
i:7 **********
i:6 **********
i:5 **********
...

Test 3

Group: 1

Verdict:

input
10 10 10
**...*...*
*..*.**.*.
...**.*..*
*...**.*..
...

correct output
4

user output
i:9 
i:8 **...*...*
i:7 *..*.**.*.
i:6 ...**.*..*
i:5 *...**.*..
...

Test 4

Group: 1

Verdict:

input
10 10 5
****......
*.*.**..**
....*.*..*
...*.***..
...

correct output
16

user output
i:9 
i:8 ****......
i:7 *.*.**..**
i:6 ....*.*..*
i:5 ...*.***..
...

Test 5

Group: 1

Verdict:

input
10 10 2
**.***..*.
...*.*....
.***.*...*
***.***..*
...

correct output
30

user output
i:9 
i:8 **.***..*.
i:7 ...*.*....
i:6 .***.*...*
i:5 ***.***..*
...

Test 6

Group: 2

Verdict:

input
500 500 1
.................................

correct output
9552040

user output
i:499 
i:498 ...........................

Test 7

Group: 2

Verdict:

input
500 500 5
.................................

correct output
1536063

user output
i:499 
i:498 ...........................

Test 8

Group: 2

Verdict:

input
500 500 25000
**...*...**..*.*..*.**.*..*.*....

correct output
288

user output
i:499 
i:498 **...*...**..*.*..*.**.*...

Test 9

Group: 2

Verdict:

input
500 500 12500
**.**.*..*...*.**...*.***........

correct output
786

user output
i:499 
i:498 **.**.*..*...*.**...*.**...

Test 10

Group: 2

Verdict:

input
500 500 5000
.*.*.**..*.*.**.**..*..**...*....

correct output
1763

user output
i:499 
i:498 .*.*.**..*.*.**.**..*..*...

Test 11

Group: 3

Verdict:

input
2000 2000 1
.................................

correct output
489611392

user output
i:1999 
i:1998 ..........................

Test 12

Group: 3

Verdict:

input
2000 2000 5
.................................

correct output
120725884

user output
i:1999 
i:1998 ..........................

Test 13

Group: 3

Verdict:

input
2000 2000 400000
..*..**.**.**.*.***...**.*..**...

correct output
1849

user output
i:1999 
i:1998 ..*..**.**.**.*.***...*...

Test 14

Group: 3

Verdict:

input
2000 2000 200000
***.*....*.*..*....**..*..*.*....

correct output
2665

user output
i:1999 
i:1998 ***.*....*.*..*....**.....

Test 15

Group: 3

Verdict:

input
2000 2000 80000
**.**...*.***.**....**.*....*....

correct output
5587

user output
i:1999 
i:1998 **.**...*.***.**....**....