ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1147. Shaping Regions

Who knew Test 11, my program always WA?
Posted by xurshid_n 8 Mar 2010 21:36
this my code:
import java.io.*;
import java.util.*;

public class Problem_1147 implements Runnable{
    public static void main(String []args){
        new Thread(new Problem_1147()).start();
    }
    public void run(){
        try{
            reader = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
            //reader = new StreamTokenizer(new BufferedReader(new FileReader("card.out")));
            //out = new PrintWriter(new FileWriter("card.out"));
            solve();
        }catch(IOException e){
            throw new IllegalStateException(e);
        }
    }

    final int COLOR_COUNT = 5501;
    final int N = 400001;
    int n;
    int width;
    int height;

    int xPos[] = new int[10001];
    int yPos[] = new int[10001];

    int color[] = new int[COLOR_COUNT];
    int x[]      = new int[1001];
    int y[]     = new int[1001];
    int z[]      = new int[1001];
    int t[]     = new int[1001];
    int cc[]    = new int[1001];
    int xc[] = new int[1009];
    int yc[] = new int[1009];

    short tColor[][] = new short[2002][2002];

    StreamTokenizer reader;

    PrintWriter out;

    int nextInt()throws IOException{
        reader.nextToken();
        return(int)reader.nval;

    }







    void solve()throws IOException{

        width = nextInt();
        height  = nextInt();
        n = nextInt();

        for (int i = 1; i<=n;i++){
            x[i] = nextInt();
            y[i] = nextInt();
            z[i] = nextInt();
            t[i] = nextInt();

            cc[i] = nextInt();
        }
        x[0] = 0;
        y[0] = 0;
        z[0] = width;
        t[0] = height;
        cc[0] = 1;

        Arrays.fill(xPos,0);
        Arrays.fill(yPos,0);

        for (int i = 0;i <=n ;i++)xPos[x[i]] = xPos[z[i]] = yPos[y[i]] = yPos[t[i]] = 1;



        for (int i = 1; i<= width; i++)xPos[i] += xPos[i-1];
        for (int i = 1; i<= height; i++)yPos[i] += yPos[i-1];

        for (int i = width; i >= 0  ; i-- ) xc[xPos[i]] = i ;
        for (int i = height; i>= 0  ; i-- ) yc[yPos[i]] = i ;

    /*    System.out.println("x coords ");
        for (int i = xPos[0] ; i<=xPos[width];i++)System.out.println(xc[i]);
        System.out.println("y coords ");
        for (int i = yPos[0] ; i<=yPos[height];i++)System.out.println(yc[i]);
    */
        for (int i = 0; i<=n;i++){
            int i_x = xPos[x[i]];
            int j_x = xPos[z[i]];
            int i_y = yPos[y[i]];
            int j_y = yPos[t[i]];
            short c = (short)cc[i];
        //    System.out.println(i_x +" " +j_x+" " +i_y+" " +j_y);
            for (int v = i_x; v < j_x; v++){
                for (int w = i_y; w  < j_y; w++){
                    tColor[v][w] = c;
                }
            }
        }

        Arrays.fill(color, 0);
        for (int i = xPos[0]; i < xPos[width]; i++){
            for (int j = yPos[0]; j < yPos[height]; j++){
                color[tColor[i][j]] += (xc[i+1] - xc[i])*(yc[j+1] - yc[j]);
            }
        }

        for (int i = 1; i<=2500;i++)if (color[i]>0)System.out.println(i+ " "+color[i]);
    }

}