Skip to content

Instantly share code, notes, and snippets.

@yaasita
Last active August 29, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaasita/10997932 to your computer and use it in GitHub Desktop.
Save yaasita/10997932 to your computer and use it in GitHub Desktop.
paiza
#!/usr/bin/perl
my (@row,@columns);
{
my $line=<STDIN>;
my ($height,$width)=split(/\s+/,$line);
for (1..$height){
$line=<STDIN>;
chomp $line;
$row[$_-1]=$line;
for(1..length($line)){
$columns[$_-1].=substr($line,$_-1,1);
}
}
}
{
my $w_first_line=<STDIN>;
for (1..$w_first_line){
my $line=<STDIN>;
my $put_count=0;
my ($height,$width)=split(/\s+/,$line);
my $pattern="";
$pattern="(?=0{".($width-1)."})" if $width>=2;
for (my $i=0;$i<=$#row;$i++){
while ($row[$i]=~/0$pattern/g){
my $h_pattern="^"."." x (pos($row[$i])-1)."0" x $width;
my $put_ok=0;
$put_ok=1 if $height==1;
for (my $j=1;$j<$height and $i+$height-1<=$#row;$j++){
unless ($row[$i+$j]=~/$h_pattern/){
$put_ok=0;
last;
}
else {
$put_ok=1;
}
}
$put_count++ if $put_ok;
}
}
print $put_count,"\n";
}
}
#!/usr/bin/perl
(@row,@columns);
$line=<STDIN>;
($height,$width)=split(/\s+/,$line);
for (1..$height){
$line=<STDIN>;
chomp $line;
$row[$_-1]=$line;
for(1..length($line)){
$columns[$_-1].=substr($line,$_-1,1);
}
}
$w_first_line=<STDIN>;
for (1..$w_first_line){
$line=<STDIN>;
$put_count=0;
($height,$width)=split(/\s+/,$line);
$pattern="";
$pattern="(?=0{".($width-1)."})" if $width>=2;
for ($i=0;$i<=$#row;$i++){
while ($row[$i]=~/0$pattern/g){
$h_pattern= '^.{' . (pos($row[$i])-1) . '}0{' . $width . '}';
$put_ok=0;
$put_ok=1 if $height==1;
for ($j=1;$j<$height and $i+$height-1<=$#row;$j++){
unless ($row[$i+$j]=~/$h_pattern/){
$put_ok=0;
last;
}
else {
$put_ok=1;
}
}
$put_count++ if $put_ok;
}
}
print $put_count,"\n";
}
#!/usr/bin/perl
$line=<STDIN>;
($height,$width)=split(/\s+/,$line);
for (1..$height){
$row[$_-1]=<STDIN>;
}
$w_first_line=<STDIN>;
for (1..$w_first_line){
$line=<STDIN>;
$put_count=0;
($height,$width)=split(/\s+/,$line);
$pattern="";
$pattern="(?=0{".($width-1)."})" if $width>=2;
for ($i=0;$i<=$#row;$i++){
while ($row[$i]=~/0$pattern/g){
$put_ok = $height == 1 ? 1 : 0;
for ($j=1;$j<$height and $i+$height-1<=$#row;$j++){
unless (substr($row[$i+$j],pos($row[$i])-1,$width) eq '0' x $width){
$put_ok=0;
last;
}
else {
$put_ok=1;
}
}
$put_count++ if $put_ok;
}
}
print $put_count,"\n";
}
#!/usr/bin/perl
$line=<STDIN>;
($height,$width)=split(/\s+/,$line);
for (1..$height){
$row[$_-1]=<STDIN>;
}
$w_first_line=<STDIN>;
for (1..$w_first_line){
$line=<STDIN>;
$put_count=0;
($height,$width)=split(/\s+/,$line);
for ($i=0;$i<=$#row;$i++){
for ($k=0;$k+$width<=length($row[$i]);$k++){
if (substr($row[$i],$k,$width) eq '0' x $width){
$put_ok = $height == 1 ? 1 : 0;
for ($j=1;$j<$height and $i+$height-1<=$#row;$j++){
unless (substr($row[$i+$j],$k,$width) eq '0' x $width){
$put_ok=0;
last;
}
else {
$put_ok=1;
}
}
$put_count++ if $put_ok;
}
}
}
print $put_count,"\n";
}
#!/usr/bin/perl
use strict;
my @row;
my ($display_height,$display_width);
{
my $line=<STDIN>;
($display_height,$display_width)=split(/\s+/,$line);
for (1..$display_height){
$row[$_-1]=<STDIN>;
}
}
{
my $w_first_line=<STDIN>;
for (1..$w_first_line){
my $line=<STDIN>;
my $put_count=0;
my ($widget_height,$widget_width)=split(/\s+/,$line);
unless ($widget_width<=$display_width and $widget_height<=$display_height){
print "0\n";
next;
}
my $pattern="";
$pattern="(?=0{".($widget_width-1)."})" if $widget_width>=2;
for (my $i=0;$i<=$#row;$i++){
while ($row[$i]=~/0$pattern/g){
my $put_ok = $widget_height == 1 ? 1 : 0;
for (my $j=1;$j<$widget_height and $i+$widget_height-1<=$#row;$j++){
unless (substr($row[$i+$j],pos($row[$i])-1,$widget_width) eq '0' x $widget_width){
$put_ok=0;
last;
}
else {
$put_ok=1;
}
}
$put_count++ if $put_ok;
}
}
print $put_count,"\n";
}
}
7 4
1000
1101
1001
1111
1111
1111
1111
3
1 2
2 3
2 1
5 5
00000
00100
00010
10001
10000
3
2 2
1 1
3 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment