Submission #1291774


Source Code Expand

#include<cstdio>
#include<vector>


using namespace std;

using vi=vector<int>;
using vvi=vector<vi>;


const int white=-1;
const int black=100000000;


vi gx, gy;


void push(int x, int y)
{
	gx.push_back(x);
	gy.push_back(y);
}


int pop(int& x, int& y)
{
	if(gx.size()<=0) return 0;
	x=gx.back();
	y=gy.back();
	gx.pop_back();
	gy.pop_back();
	return 1;
}


void eng_fill(vvi& c, int x, int y, int g)
{
	int vx[]={ 1, 0,-1, 0};
	int vy[]={ 0,-1, 0, 1};
	int nx, ny;
	int w, h;

	w=7;
	h=c.size();
	push(x, y);
	c[y][x]=g;
	while(pop(x, y))
	{
		for(int i=0;i<4;i++)
		{
			nx=x+vx[i];
			ny=y+vy[i];
			if(nx<0 || w<=nx || ny<0 || h<=ny) continue;
			if(c[ny][nx]!=white) continue;
			c[ny][nx]=g;
			push(nx, ny);
		}
	}
}



int engroup(vvi& c)
{
	int w, h, x, y;
	int g=0;

	w=7;
	h=c.size();
	for(y=0;y<h;y++)
	{
		for(x=0;x<w;x++)
		{
			if(c[y][x]!=white) continue;
			eng_fill(c, x, y, g);
			g++;
		}
	}
	return g;
}


int gcd(int a, int b)
{
	int c;
	while((c=a%b))
	{
		a=b;
		b=c;
	}
	return b;
}


int lcm(int a, int b)
{
	return a/gcd(a, b)*b;
}


int main(void)
{
	int n, m, q, g1, g2, h, uh;
	vvi c, f;
	vi a;

	while(scanf("%d%d%d", &n, &m, &q)==3)
	{
		a.resize(n);
		for(int i=0;i<q;i++) scanf("%d", &a[i]);

		uh=lcm(m, 7)/7;
		h=n/uh;

		c.clear();
		c.resize(uh);
		for(auto& ce: c) ce.resize(7, white);
		for(int i=0;i<q;i++)
		{
			for(int j=a[i];j<uh*7;j+=m)
			{
				c[j/7][j%7]=black;
			}
		}
		g1=engroup(c);

		c.clear();
		c.resize(uh*2);
		for(auto& ce: c) ce.resize(7, white);
		for(int i=0;i<q;i++)
		{
			for(int j=a[i];j<uh*2*7;j+=m)
			{
				c[j/7][j%7]=black;
			}
		}
		g2=engroup(c);

		printf("%d\n", g1+(g2-g1)*(h-1));
	}

	return 0;
}

Submission Info

Submission Time
Task C - Calendar 2
User myanta
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1823 Byte
Status RE
Exec Time 1092 ms
Memory 15308 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:110:42: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   for(int i=0;i<q;i++) scanf("%d", &a[i]);
                                          ^

Judge Result

Set Name Sample Subtask1 Subtask2 Subtask3 Subtask4
Score / Max Score 0 / 0 100 / 100 0 / 90 0 / 200 0 / 110
Status
AC × 2
AC × 7
MLE × 1
MLE × 1
RE × 2
AC × 7
TLE × 1
MLE × 1
RE × 3
Set Name Test Cases
Sample sub0_in1.txt, sub0_in2.txt
Subtask1 sub0_in1.txt, sub0_in2.txt, sub1_in1.txt, sub1_in2.txt, sub1_in3.txt, sub1_in4.txt, sub1_in5.txt
Subtask2 sub2_in1.txt
Subtask3 sub2_in1.txt, sub3_in1.txt, sub3_in2.txt
Subtask4 sub0_in1.txt, sub0_in2.txt, sub1_in1.txt, sub1_in2.txt, sub1_in3.txt, sub1_in4.txt, sub1_in5.txt, sub2_in1.txt, sub3_in1.txt, sub3_in2.txt, sub4_in1.txt, sub4_in2.txt
Case Name Status Exec Time Memory
sub0_in1.txt AC 1 ms 256 KB
sub0_in2.txt AC 1 ms 256 KB
sub1_in1.txt AC 1 ms 256 KB
sub1_in2.txt AC 1 ms 256 KB
sub1_in3.txt AC 1 ms 256 KB
sub1_in4.txt AC 1 ms 256 KB
sub1_in5.txt AC 56 ms 15308 KB
sub2_in1.txt MLE 997 ms -1923748 KB
sub3_in1.txt RE 299 ms 628 KB
sub3_in2.txt RE 97 ms 256 KB
sub4_in1.txt RE 99 ms 384 KB
sub4_in2.txt TLE 1092 ms -1353228 KB