Submission #486276

# Submission time Handle Problem Language Result Execution time Memory
486276 2021-11-11T05:44:53 Z kiomi Nautilus (BOI19_nautilus) C++14
66 / 100
34 ms 2596 KB
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("Ofast")
//#pragma GCC optimization ("unroll-loops")

//#pragma comment(linker,"/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

//order_of_key(k): Number of items strictly smaller than k .
//find_by_order(k): K-th element in a set (counting from zero).
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define full(x,n) x,x+n+1
#define full(x) x.begin(),x.end()
#define finish return 0

#define putb push_back
#define f first
#define s second

//logx(a^n)=loga(a^n)/logx(a)
//logx(a*b)=logx(a)+logx(b)
//logx(y)=log(y)/log(x)
//logb(n)=loga(n)/loga(b)

#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define putf push_front
#define gainb pop_back

//(a+b)^n=sum of C(n,i)*a^i*b^(n-i) 0<=i<=n
//(a-b)^n=sum of C(n,i)*a^i*b^(n-i) for even i-for odd i

#define gainf pop_front
#define len(x) (int)x.size()

// 1/b%mod=b^(m-2)%mod
// (a>>x)&1==0
// a^b=(a+b)-2(a&b)

typedef double db;
typedef long long ll;

//sum of squares n*(n+1)*(2n+1)/6
//sum of cubes [n*(n+1)/2]^2
//sum of squares for odds n*(4*n*n-1)/3
//sum of cubes for odds n*n*(2*n*n-1)

const int ary=1e2+5;
const ll mod=1e9+7;
const ll inf=1e18;

using namespace std;
using namespace __gnu_pbds;
int r,c,m,ans;
pair<bool,bool> dp[ary][ary][ary];
string s;
char a[ary][ary];
void rec(int x,int y,int k){
	if(x<1||x>r||y<1||y>c||a[x][y]=='#'||dp[x][y][k].f){
		return;
	}
	dp[x][y][k].f=1;
	if(k==0){
		dp[x][y][k].s=1;
		return;
	}
	if(s[k-1]=='S'||s[k-1]=='?'){
		rec(x-1,y,k-1);
		dp[x][y][k].s=(dp[x][y][k].s||dp[x-1][y][k-1].s);
	}
	if(s[k-1]=='W'||s[k-1]=='?'){
		rec(x,y+1,k-1);
		dp[x][y][k].s=(dp[x][y][k].s||dp[x][y+1][k-1].s);
	}
	if(s[k-1]=='N'||s[k-1]=='?'){
		rec(x+1,y,k-1);
		dp[x][y][k].s=(dp[x][y][k].s||dp[x+1][y][k-1].s);
	}
	if(s[k-1]=='E'||s[k-1]=='?'){
		rec(x,y-1,k-1);
		dp[x][y][k].s=(dp[x][y][k].s||dp[x][y-1][k-1].s);
	}
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>r>>c>>m;
	for(int i=1;i<=r;i++){
		for(int j=1;j<=c;j++){
			cin>>a[i][j];
		}
	}
	cin>>s;
	for(int i=1;i<=r;i++){
		for(int j=1;j<=c;j++){
			rec(i,j,m);
			ans+=dp[i][j][m].s;
		}
	}
	cout<<ans;
}

Compilation message

nautilus.cpp:15: warning: "full" redefined
   15 | #define full(x) x.begin(),x.end()
      | 
nautilus.cpp:14: note: this is the location of the previous definition
   14 | #define full(x,n) x,x+n+1
      |
# Verdict Execution time Memory Grader output
1 Correct 15 ms 2508 KB Output is correct
2 Correct 3 ms 2508 KB Output is correct
3 Correct 2 ms 2380 KB Output is correct
4 Correct 2 ms 2508 KB Output is correct
5 Correct 2 ms 2408 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 2508 KB Output is correct
2 Correct 3 ms 2508 KB Output is correct
3 Correct 2 ms 2380 KB Output is correct
4 Correct 2 ms 2508 KB Output is correct
5 Correct 2 ms 2408 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 28 ms 2380 KB Output is correct
8 Correct 7 ms 2500 KB Output is correct
9 Correct 2 ms 2508 KB Output is correct
10 Correct 2 ms 2380 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 34 ms 2416 KB Output is correct
13 Correct 31 ms 2596 KB Output is correct
14 Correct 23 ms 2504 KB Output is correct
15 Correct 3 ms 2380 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 34 ms 2468 KB Output is correct
18 Correct 34 ms 2456 KB Output is correct
19 Correct 15 ms 2400 KB Output is correct
20 Correct 6 ms 2380 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 2508 KB Output is correct
2 Correct 3 ms 2508 KB Output is correct
3 Correct 2 ms 2380 KB Output is correct
4 Correct 2 ms 2508 KB Output is correct
5 Correct 2 ms 2408 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 28 ms 2380 KB Output is correct
8 Correct 7 ms 2500 KB Output is correct
9 Correct 2 ms 2508 KB Output is correct
10 Correct 2 ms 2380 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 34 ms 2416 KB Output is correct
13 Correct 31 ms 2596 KB Output is correct
14 Correct 23 ms 2504 KB Output is correct
15 Correct 3 ms 2380 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 34 ms 2468 KB Output is correct
18 Correct 34 ms 2456 KB Output is correct
19 Correct 15 ms 2400 KB Output is correct
20 Correct 6 ms 2380 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Runtime error 3 ms 716 KB Execution killed with signal 11
23 Halted 0 ms 0 KB -