Skip to content

Instantly share code, notes, and snippets.

@modos
Created September 23, 2022 21:22
Show Gist options
  • Save modos/ddf82945c75d48421d2951c8d138e0ea to your computer and use it in GitHub Desktop.
Save modos/ddf82945c75d48421d2951c8d138e0ea to your computer and use it in GitHub Desktop.
دورگیری
#include <iostream>
using namespace std;
inline int in() { int x; scanf("%d", &x); return x; }
const int N = 2002;
int main()
{
long long p = 0;
char c1, c2;
cin >> c1 >> c2;
if(c2 == 'K')
{
cout << 1 << endl;
return 0;
}
int x1 = 0, y1 = 0, x2, y2;
char startC2 = c2;
bool done = 0;
while(!done)
{
c1 = c2;
cin >> c2;
x2 = x1;
y2 = y1;
if(c2 == 'K')
{
done = 1;
c2 = startC2;
}
switch(c1)
{
case 'E': switch(c2)
{
case 'E': x2++; break;
case 'N': y2++; x2++; p++; break;
case 'W': y2++; p += 2; break;
};
break;
case 'N': switch(c2)
{
case 'N': y2++; break;
case 'W': x2--; y2++; p++; break;
case 'S': x2--; p += 2; break;
};
break;
case 'W': switch(c2)
{
case 'W': x2--; break;
case 'S': x2--; y2--; p++; break;
case 'E': y2--; p += 2; break;
};
break;
case 'S': switch(c2)
{
case 'S': y2--; break;
case 'E': x2++; y2--; p++; break;
case 'N': x2++; p += 2; break;
};
break;
};
p += 1LL*x1*y2 - 1LL*x2*y1;
x1 = x2;
y1 = y2;
}
p /= 2;
cout << p << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment