Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- import java.io.BufferedReader;
- import java.awt.Point;
- public class team{
- public static final String TASKNAME = "team";
- public static long mod= 1000000009;
- public static Debug db;
- public static void main(String[] args) throws IOException {
- // InputReader in = new InputReader(System.in);
- // PrintWriter out = new PrintWriter(System.out);
- InputReader in = new InputReader(new FileInputStream(TASKNAME+".in"));
- PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(TASKNAME+".out")));
- Autocompletion solver = new Autocompletion();
- db=new Debug(System.getSecurityManager()==null);
- solver.solve(1, in, out);
- out.close();
- }
- static class Autocompletion {
- public void solve(int testNumber, InputReader in, PrintWriter out) {
- int n=in.nextInt();
- int m=in.nextInt();
- int k=in.nextInt();
- long dp[][][]=new long[n][m][k+2];
- long fj[]=new long[n];
- long fp[]=new long[m];
- for(int i=0;i<n;i++) {
- fj[i]=in.nextLong();
- }
- for(int i=0;i<m;i++) {
- fp[i]=in.nextLong();
- }
- for(int i=0;i<=k;i++) {
- for(int j=0;j<n;j++) {
- for(int l=0;l<m;l++) {
- if(j!=0) {
- dp[j][l][i]=(dp[j][l][i]+dp[j-1][l][i])%mod;
- }
- if(l!=0) {
- dp[j][l][i]=(dp[j][l][i]+dp[j][l-1][i])%mod;
- }
- if(l!=0 && j!=0) {
- dp[j][l][i]=(dp[j][l][i]-dp[j-1][l-1][i])%mod;
- }
- if(fj[j]>fp[l]) {
- if(i==0) {
- dp[j][l][i+1]=1;
- }
- else if(j==0 || l==0) {//not possible since i>0
- continue;
- }
- else {
- dp[j][l][i+1]=(dp[j][l][i+1]+dp[j-1][l-1][i])%mod;
- }
- }
- }
- }
- }
- long sum=0;
- for(int i=0;i<n;i++) {
- for(int j=0;j<m;j++) {
- if(fj[i]>fp[j] && i!=0 && j!=0){
- sum=(sum+dp[i-1][j-1][k-1])%mod;
- }
- }
- }
- out.println(sum%mod);
- }
- private void timeout() {
- ArrayList<Integer> arr=new ArrayList<Integer>();
- for(int i=0;i<Integer.MAX_VALUE;i++) {
- arr.add(i);
- }
- }
- }
- static class Pair implements Comparable<Pair>{
- int x;
- int y;
- Pair(int a, int b){
- x=a;
- y=b;
- }
- @Override
- public int compareTo(Pair arg0) {
- if(arg0.x!=x)return x-arg0.x;
- return y-arg0.y;
- }
- }
- static class Triple implements Comparable<Triple>{
- int x;
- int y;
- int z;
- Triple(int a, int b, int c){
- x=a;
- y=b;
- z=c;
- }
- @Override
- public int compareTo(Triple arg0) {
- if(arg0.x!=x)return x-arg0.x;
- return y-arg0.y;
- }
- }
- static class InputReader {
- public BufferedReader reader;
- public StringTokenizer tokenizer;
- public InputReader(InputStream stream) {
- reader = new BufferedReader(new InputStreamReader(stream), 32768);
- tokenizer = null;
- }
- public String next() {
- while (tokenizer == null || !tokenizer.hasMoreTokens()) {
- try {
- tokenizer = new StringTokenizer(reader.readLine());
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- return tokenizer.nextToken();
- }
- public int nextInt() {
- return Integer.parseInt(next());
- }
- public long nextLong() {
- return Long.parseLong(next());
- }
- public int[] nextIntArr(int n) {
- int arr[]=new int[n];
- for(int i=0;i<n;i++) {
- arr[i]=this.nextInt();
- }
- return arr;
- }
- }
- public static class Debug {
- private boolean allowDebug;
- public Debug(boolean allowDebug) {
- this.allowDebug = allowDebug;
- }
- private void outputName(String name) {
- System.out.print(name + " = ");
- }
- public void debug(String name, int x) {
- if (!allowDebug) {
- return;
- }
- outputName(name);
- System.out.println("" + x);
- }
- public void debug(String name, long x) {
- if (!allowDebug) {
- return;
- }
- outputName(name);
- System.out.println("" + x);
- }
- public void debug(String name, double x) {
- if (!allowDebug) {
- return;
- }
- outputName(name);
- System.out.println("" + x);
- }
- public void debug(String name, int[] x) {
- if (!allowDebug) {
- return;
- }
- outputName(name);
- System.out.println(Arrays.toString(x));
- }
- public void debug(String name, long[] x) {
- if (!allowDebug) {
- return;
- }
- outputName(name);
- System.out.println(Arrays.toString(x));
- }
- public void debug(String name, double[] x) {
- if (!allowDebug) {
- return;
- }
- outputName(name);
- System.out.println(Arrays.toString(x));
- }
- public void debug(String name, Pair[] x) {
- if (!allowDebug) {
- return;
- }
- outputName(name);
- StringBuilder sb = new StringBuilder("[");
- int cnt=0;
- for(Pair y:x) {
- sb.append('('+y.x+","+y.y+')');
- if (cnt != x.length-1)sb.append(", ");
- cnt++;
- }
- System.out.println(sb.append("]").toString());
- }
- public void debug(String name, Object x) {
- if (!allowDebug) {
- return;
- }
- outputName(name);
- System.out.println("" + x);
- }
- public void debug(String name, Object... x) {
- if (!allowDebug) {
- return;
- }
- outputName(name);
- System.out.println(Arrays.deepToString(x));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement